Set Headers Using Middleware in Laravel 5
How to set headers using middleware in Laravel 5? The steps are as follows:
1. Create a middleware using artisan.
php artisan make:middleware RevalidateBackHistory
2. Within RevalidateBackHistory middleware, we set the header to no-cache and revalidate.
3. Update the application’s route middleware in Kernel.php
protected $routeMiddleware = [ . . 'revalidate' => \App\Http\Middleware\RevalidateBackHistory::class, . . ];
4. And that’s all! So basically you just need to call revalidate middleware for routes which require user authentication.