This Laravel package contains a handler for the If-Modified-Since request and Last-Modified response headers.
You can install the package via composer:
composer require kudashevs/laravel-last-modifiedThen, register the middleware in the app/Http/Kernel.php:
protected $middleware = [
'web' => [
...
\Kudashevs\LaravelLastModified\Middleware\LastModified::class,
],
];You may also want to publish the configuration file (optional).
php artisan vendor:publish --provider="Kudashevs\LaravelLastModified\Providers\LastModifiedServiceProvider"After deploying your application, check whether the headers are handled correctly.
First, the middleware identifies the last modification time of a given url by parsing the request. It tries to retrieve this information from possible origins in the following order (if it cannot retrieve the information, it moves forward):
- a first model in the view data,
- a first collection in the view data,
- a first paginator in the view data,
- a compiled view file,
- a view file,
- as a last resort, a fallback.
After the last modification time has been retrieved, the middleware sets the Last-Modified response header. Then,
it handles the If-Modified-Since request header using the last modification time from the previous step.
After publishing, the configuration settings are located in the config/last-modified.php file.
There configuration options are currently supported:
'enable' # A boolean defines whether the middleware is enabled (default `true`).
'aggressive' # A boolean defines whether the middleware returns a response immediately (default is `false`).
'fallback' # An integer the fallback timestamp for the Last-Modifier header.
'origins' # An array with a list of origins of the last modification time.
'exclude' # An array with a list of paths to be excluded from processing.
, for more information please see the configuration file.
composer testPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Note: Please make sure to update tests as appropriate.
The MIT License (MIT). Please see the License file for more information.