Easily setting the Last-Modified
header and 304 Not Modified
response code.
- PHP 7.4 - 8.3
- Laravel 8.x - 11.x
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"
The setup is very simple and consists of two steps:
// in app/Http/Kernel.php
protected $middleware = [
'web' => [
// other middleware
\Abordage\LastModified\Middleware\LastModifiedHandling::class,
],
];
<?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.
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
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
If you have any feedback, comments or suggestions, please feel free to open an issue within this repository.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.