首页 文章

会话到期后将用户重定向到登录页面 - Laravel 5

提问于
浏览
0

目标

我正在尝试将用户的会话过期或注销后立即重定向到我的登录页面 .

Example :

如果他们注销,并尝试单击任何链接,他们应该被重定向到登录页面 .


我有这样的登录路线

Route::get('/',['as' => 'login', 'uses'=>'AuthController@getSignIn']);

然后,我尝试在 config/session.php 配置它

/*
|--------------------------------------------------------------------------
| Session Lifetime
|--------------------------------------------------------------------------
|
| Here you may specify the number of minutes that you wish the session
| to be allowed to remain idle before it expires. If you want them
| to immediately expire on the browser closing, set that option.
|
*/

'lifetime' => 120,
'expire_on_close' => true,
'expired-session-redirect' => url('/')

一旦我的用户会话过期,我点击其他链接,我没有重定向到我的登录页面?

它崩溃并返回白色空页

enter image description here


我还需要做些什么来实现这样的目标呢?

How would one go about and debug this further ?


我现在正在接受任何建议 .

任何提示/建议/帮助将非常感谢!

1 回答

  • 1

    用于重定向那些不希望允许已注销用户访问的用户 . 有关Laravel middleware documentation的更多信息 .

    对于单一路线:

    Route::get('profile', function () {
        // Only authenticated users may enter...
    })->middleware('auth');
    

    对于路线组:

    Route::group(['middleware' => ['auth']], function () {
        //
    });
    

    这取决于您使用哪个版本的Laravel来确定如何设置用户重定向到的位置 .

相关问题