abordage / laravel-last-modified
Setting the Last-Modified header and 304 Not Modified response code if the page hasn't changed since the last visit
Installs: 8 482
Dependents: 0
Suggesters: 0
Security: 0
Stars: 12
Watchers: 2
Forks: 3
Open Issues: 1
Requires
- php: >=7.4
- illuminate/support: ^8.0 || ^9.0 || ^10.0 || ^11.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- nunomaduro/collision: ^5.0 || ^6.0 || ^7.0 || ^8.0
- nunomaduro/larastan: ^1.0 || ^2.0
- orchestra/testbench: ^6.0 || ^7.0 || ^8.0 || ^9.0
- phpunit/phpunit: ^9.5 || ^10.0
This package is auto-updated.
Last update: 2024-11-11 23:30:51 UTC
README
Last-Modified / 304 Not Modified Handler for Laravel
Easily setting the Last-Modified
header and 304 Not Modified
response code.
Requirements
- PHP 7.4 - 8.3
- Laravel 8.x - 11.x
Installation
You can install the package via composer:
composer require abordage/laravel-last-modified
Optionally, you can publish the config file with:
php artisan vendor:publish --tag="last-modified-config"
Usage
The setup is very simple and consists of two steps:
Registering middleware
// in app/Http/Kernel.php protected $middleware = [ 'web' => [ // other middleware \Abordage\LastModified\Middleware\LastModifiedHandling::class, ], ];
Set Last Update Date in your Controller
<?php namespace App\Http\Controllers; use App\Http\Controllers\Controller; use LastModified; class PostController extends Controller { public function show($id) { $post = \App\Models\Post::findOrFail($id); LastModified::set($post->updated_at); return view('posts.show', ['post' => $post]); } }
It's all. Now you can check the headers.
How to check headers
You can check headers in the browser console under the Network
tab (make sure Disable Cache
is off)
or
using https://last-modified.com/en
Testing
composer test:all
or
composer test:phpunit composer test:phpstan composer test:phpcsf
or see https://github.com/abordage/laravel-last-modified/actions/workflows/tests.yml
Feedback
If you have any feedback, comments or suggestions, please feel free to open an issue within this repository.
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.