因为我是 Laravel 的新手。所以在 Laravel 5.7 中,我以自己的方式解决了这个问题。
使用 artisan 创建中间件。
php artisan make:middleware RevalidateBackHistory
在 RevalidateBackHistory 中间件中,我们将标头设置为 no-cache 并重新验证。
<?php
namespace App\Http\Middleware;
use Closure;
class RevalidateBackHistory
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$response = $next($request);
return $response->header('Cache-Control','nocache, no-store, max-age=0, must-revalidate')
->header('Pragma','no-cache')
->header('Expires','Fri, 01 Jan 1990 00:00:00 GMT');
}
}
在 Kernel.php 中更新应用的路由中间件
protected $routeMiddleware = [
.
.
'revalidate' => \App\Http\Middleware\RevalidateBackHistory::class,
.
.
];
在 Web.php 中更新路由。就我而言。
Route::group(['middleware' => 'revalidate'], function(){
Route::get('/', 'HomeController@index');
Route::get('/home', 'HomeController@index');
Route::get('/dashboard', 'HomeController@index');
});
仅此而已!所以基本上你只需要为需要用户身份验证的路由调用 revalidate 中间件。
这是我关注的网址
Prevent Browser's Back Button Login After Logout in Laravel 5
https://www.youtube.com/watch?v=wLkA1g2s65U