Sending Last-Modified header, 304 Not Modified status on Laravel
1. Install the package:
composer require abordage/laravel-last-modified
2. Middleware registration:
// in app/Http/Kernel.php
protected $middleware = [
'web' => [
// ...
\Abordage\LastModified\Middleware\LastModifiedHandling::class,
],
// ...
];
3. Setting last-modified in the controller:
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Models\Post;
use LastModified;
class PostController extends Controller
{
public function show($id)
{
$post = Post::findOrFail($id);
LastModified::set($post->updated_at);
return view('posts.show', ['post' => $post]);
}
}
More info: https://github.com/abordage/laravel-last-modified