Browser’s Back Button Issue After Logout in Laravel 5

laravel 8

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.

This content is for members only.
Please . Not a Member? Join Us

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.