[英]Automatically redirect to login page when session timeout in laravel 5.4
I'm working on Laravel 5.4.我正在研究 Laravel 5.4。 Without making a request pages must redirect to login page when session is timed out.当 session 超时时,如果不发出请求,页面必须重定向到登录页面。 I don't want any Javascript code.我不想要任何 Javascript 代码。 I tried but its not working well for multiple tabs.我尝试过,但它不适用于多个标签。 I even tried with Middleware but that did not work.我什至尝试过使用中间件,但没有奏效。 References I tried:我试过的参考资料:
Is there any solution to solve this issue in Larvel 5.4 framework, directly redirect to login page after session timeout.在Larvel 5.4框架中是否有解决此问题的解决方案,在session超时后直接重定向到登录页面。
You can catch the 419 error in the render function of App\Exceptions\Handler.您可以在 App\Exceptions\Handler 的渲染 function 中捕获 419 错误。
Something like this像这样的东西
if (method_exists($exception, 'getStatusCode') && $exception->getStatusCode() == '419') {
//your custom handler here
}
return parent::render($request, $exception);
Try this尝试这个
protected $middleware = [
'Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode',
'Illuminate\Cookie\Middleware\EncryptCookies',
'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse',
'Illuminate\Session\Middleware\StartSession',
'Illuminate\View\Middleware\ShareErrorsFromSession',
'App\Http\Middleware\VerifyCsrfToken',
'App\Http\Middleware\Authenticate',// add this line according to your namespace if not found in your kernel.php
];
you just add your route in this middleware您只需在此中间件中添加您的路线
Route::get('/admin-someting', ['middleware' => 'auth', function () {
//your route
}]);
or this put on your controller或者这个放在你的 controller
public function __construct()
{
$this->middleware('auth');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.