Laravel-重定向到倒数第二个url


Laravel - redirect to second to last url

是否可以在身份验证之后将用户重定向到倒数第二页?

为什么
我在覆盖中打开登录。当验证抛出错误时,重定向为:

return Redirect::intended('?openOverlay=login')->with('error-login-noconfirm','1');  

当用户输入正确的登录数据时,重定向为back(),这意味着他将被重定向到右侧页面,但带有打开的Overlay。

当用户成功登录时,我需要去掉覆盖,这意味着,我可能需要将路由传递给登录方法,或者类似的东西。

你有主意吗?谢谢

编辑:
登录代码:

    if ($validator->fails()) {
        return Redirect::intended('?openOverlay=login')
            ->withErrors($validator)
            ->withInput(Input::except('password'));
    } else {
        $user = User::where('email', Input::get('email'))->first();
        if (Auth::attempt(array('email' => Input::get('email'), 'password' => Input::get('password'), 'confirmed' => 1))) {
            return Redirect::intended();
        } else {
            return Redirect::intended('?openOverlay=login')->with('error-login-noconfirm','1');
        }
    }

intended也不起作用。它将我重定向到我的/页面,而不是"最后"页面。

您不必使用back()。登录过程是这样工作的:

1) 一个"仍然没有登录"的用户试图浏览你的网站并点击一条路线:

Route::get('dashboard', 'DashboardController@dashboard');

2) 但被重定向到登录表单:

return Redirect::to('?openOverlay=login');

3) 成功登录后,您必须使用Redirect::intended()将用户重定向到他/她第一次尝试访问的url:

if (Auth::attempt(array('email' => $email, 'password' => $password)))
{
    // Login succeeded, redirect it to the intended url
    return Redirect::intended('home');
}
else
{
    /// Login failed, redirect back to login, so your user can try to login again
    return Redirect::back()->with('error-login-noconfirm','1');
}

您的用户将被重定向到"仪表板","主页"是一个后备路线,以防会话发生了什么事情,并且上面没有更多的预定("仪表盘")url。

如果预期的url不是第一个访问的url,您可以在会话:中更改它

$path = Session::put('url.intended', $the_actual_url_intended);