{"id":28522746,"url":"https://github.com/thedragoncode/last-modified","last_synced_at":"2025-07-04T02:35:26.459Z","repository":{"id":37183742,"uuid":"167387916","full_name":"TheDragonCode/last-modified","owner":"TheDragonCode","description":"Setting the response code 304 Not Modified in the absence of content changes.","archived":false,"fork":false,"pushed_at":"2025-02-24T17:15:36.000Z","size":303,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-03T12:25:01.303Z","etag":null,"topics":["304","laravel","last-modified","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TheDragonCode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":["https://boosty.to/dragon-code","https://yoomoney.ru/to/410012608840929","https://www.donationalerts.com/r/dragon_code"]}},"created_at":"2019-01-24T15:14:49.000Z","updated_at":"2025-02-24T17:15:15.000Z","dependencies_parsed_at":"2023-12-30T10:32:53.841Z","dependency_job_id":"651bc5b1-3d70-476a-b9a6-26681195bfdf","html_url":"https://github.com/TheDragonCode/last-modified","commit_stats":{"total_commits":206,"total_committers":4,"mean_commits":51.5,"dds":0.3106796116504854,"last_synced_commit":"046a435329964e042993aaa0bcbf015776791d77"},"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"purl":"pkg:github/TheDragonCode/last-modified","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheDragonCode%2Flast-modified","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheDragonCode%2Flast-modified/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheDragonCode%2Flast-modified/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheDragonCode%2Flast-modified/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TheDragonCode","download_url":"https://codeload.github.com/TheDragonCode/last-modified/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheDragonCode%2Flast-modified/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263434618,"owners_count":23465993,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["304","laravel","last-modified","php"],"created_at":"2025-06-09T09:31:12.485Z","updated_at":"2025-07-04T02:35:26.444Z","avatar_url":"https://github.com/TheDragonCode.png","language":"PHP","funding_links":["https://boosty.to/dragon-code","https://yoomoney.ru/to/410012608840929","https://www.donationalerts.com/r/dragon_code"],"categories":[],"sub_categories":[],"readme":"## Last Modified for Laravel\n\n\u003cimg src=\"https://preview.dragon-code.pro/TheDragonCode/last-modified.svg?brand=laravel\" alt=\"Laravel Last Modified\"/\u003e\n\n[![Stable Version][badge_stable]][link_packagist]\n[![Unstable Version][badge_unstable]][link_packagist]\n[![Total Downloads][badge_downloads]][link_packagist]\n[![Github Workflow Status][badge_build]][link_build]\n[![License][badge_license]][link_license]\n\n\u003e Setting the response code 304 Not Modified in the absence of content changes.\n\n\n## Installation\n\nTo get the latest version of `Last Modified` simply require the project using [Composer](https://getcomposer.org):\n\n```bash\n$ composer require dragon-code/last-modified\n```\n\nInstead, you may of course manually update your require block and run `composer update` if you so choose:\n\n```json\n{\n    \"require\": {\n        \"dragon-code/last-modified\": \"^4.0\"\n    }\n}\n```\n\nAnd call `php artisan vendor:publish --provider=\"DragonCode\\LastModified\\ServiceProvider\"` command.\n\n\u003e Note\n\u003e\n\u003e If you were using version 2.0 or less, run the `php artisan migrate` command.\n\u003e If this is your first time here, then you do not need to install this command, since, starting from version [2.1](https://github.com/TheDragonCode/last-modified/releases/tag/v2.1.0), we refused to store data in the database, replacing the storage with a cache. \n\nNext, add middleware in `$middlewareGroups \u003e web` section in `app/Http/Kernel.php` file:\n\n```php\nuse DragonCode\\LastModified\\Middlewares\\CheckLastModified;\n\nprotected $middlewareGroups = [\n    'web' =\u003e [\n         CheckLastModified::class,\n    ]\n]\n```\n\n**IMPORTANT!** It's recommended to add a middleware after `CheckForMaintenanceMode::class`.\n\nThe system works like this: when opening a page, the middleware checks if there is an entry in the database table about this link. If there is, it checks the `Last-Modified` header\nkey and returns either 200 or 304 code.\n\nTo add records to the table, it is recommended to create a console command in your application using the following example:\n\n\n## Create / Update\n\n```php\nuse Carbon\\Carbon;\nuse DragonCode\\LastModified\\Resources\\Item;\nuse DragonCode\\LastModified\\Services\\LastModified;\n\npublic function handle()\n{\n    $collection_1 = Foo::whereIsActive(true)-\u003eget();\n    $collection_2 = Bar::where('id', '\u003e', 50)-\u003eget();\n    $collection_3 = Baz::query()-\u003eget();\n\n    $builder_1 = Foo::whereIsActive(true);\n    $builder_2 = Bar::where('id', '\u003e', 50);\n    $builder_3 = Baz::query();\n    \n    $model_1 = Foo::whereIsActive(true)-\u003efirst();\n    $model_2 = Bar::where('id', '\u003e', 50)-\u003efirst();\n    $model_3 = Baz::query()-\u003efirst();\n    \n    $item_1 = Item::make(['url' =\u003e 'https://example.com/foo',      'updated_at' =\u003e Carbon::now());\n    $item_2 = Item::make(['url' =\u003e 'https://example.com/bar',      'updated_at' =\u003e Carbon::parse('2018-03-02'));\n    $item_3 = Item::make(['url' =\u003e 'https://example.com/baz?id=1', 'updated_at' =\u003e Carbon::now());\n    \n    LastModified::make()\n        -\u003ecollections($collection_1, $collection_2, $collection_3)\n        -\u003ebuilders($builder_1, $builder_2, $builder_3)\n        -\u003emodels($model_1, $model_2, $model_3)\n        -\u003emanual($item_1, $item_2, $item_3)\n        -\u003eupdate();\n}\n```\n\n**IMPORTANT!** The `url` attribute must be available for models.\n\nIf the model has no attribute `url`, it should be created.\n\nFor example:\n\n```php\nprotected getUrlAttribute(): string\n{\n    $slug = $this-\u003eslug;\n\n    return route('page.show', compact('slug'));\n}\n```\n\n## Delete\n\n```php\nuse Carbon\\Carbon;\nuse DragonCode\\LastModified\\Resources\\Item;\nuse DragonCode\\LastModified\\Services\\LastModified;\n\npublic function handle()\n{    \n    $collection_1 = Foo::whereIsActive(false)-\u003eget();\n    $collection_2 = Bar::whereIn('id', [50, 60, 62, 73])-\u003eget();\n\n    $builder_1 = Foo::whereIsActive(true);\n    $builder_2 = Bar::where('id', '\u003e', 50);\n    $builder_3 = Baz::query();\n    \n    $model_1 = Foo::whereIsActive(false)-\u003efirst();\n    $model_2 = Bar::whereIn('id', [50, 60, 62, 73])-\u003efirst();\n    \n    $item_1 = Item::make(['url' =\u003e 'https://example.com/foo', 'updated_at' =\u003e Carbon::now()]);\n    $item_2 = Item::make(['url' =\u003e 'https://example.com/bar', 'updated_at' =\u003e Carbon::now()]);\n    \n    LastModified::make()\n        -\u003ecollections($collection_1, $collection_2, $collection_3)\n        -\u003ebuilders($builder_1, $builder_2, $builder_3)\n        -\u003emodels($model_1, $model_2, $model_3)\n        -\u003emanual($item_1, $item_2, $item_3)\n        -\u003edelete();\n}\n```\n\n## Observer\n\nIn order to reduce the load on the database and free up the crown queue, it is recommended to use the observer to update the records:\n\n```php\nnamespace App\\Observers;\n\nuse Illuminate\\Database\\Eloquent\\Model;\nuse DragonCode\\LastModified\\Services\\LastModified;\n\nclass LastModifiedObserver\n{\n    public function saving(Model $model)\n    {\n        LastModified::make()\n            -\u003emodels($model)\n            -\u003eupdate();\n    }\n\n    public function deleting(Model $model)\n    {\n        LastModified::make()\n            -\u003emodels($model)\n            -\u003edelete();\n    }\n}\n```\n\nDon't forget to add the link to the service provider:\n\n```php\nnamespace App\\Providers;\n\nuse App\\Observers\\LastModifiedObserver;\nuse Illuminate\\Foundation\\Auth\\User;\nuse Illuminate\\Support\\ServiceProvider;\n\nclass ObserverServiceProvider extends ServiceProvider\n{\n    public function boot()\n    {\n        Page::observe(LastModifiedObserver::class);\n        News::observe(LastModifiedObserver::class);\n\n        // ...\n    }\n}\n```\n\n## License\n\nThis package is licensed under the [MIT License](LICENSE).\n\n\n[badge_build]:          https://img.shields.io/github/actions/workflow/status/TheDragonCode/last-modified/phpunit.yml?style=flat-square\n\n[badge_downloads]:      https://img.shields.io/packagist/dt/dragon-code/last-modified.svg?style=flat-square\n\n[badge_license]:        https://img.shields.io/packagist/l/dragon-code/last-modified.svg?style=flat-square\n\n[badge_stable]:         https://img.shields.io/github/v/release/TheDragonCode/last-modified?label=stable\u0026style=flat-square\n\n[badge_unstable]:       https://img.shields.io/badge/unstable-dev--main-orange?style=flat-square\n\n[link_build]:           https://github.com/TheDragonCode/last-modified/actions\n\n[link_license]:         LICENSE\n\n[link_packagist]:       https://packagist.org/packages/dragon-code/last-modified\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthedragoncode%2Flast-modified","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthedragoncode%2Flast-modified","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthedragoncode%2Flast-modified/lists"}