重定向到索引(如果经过身份验证)


Redirect to index if authenticated

我是拉拉维尔的新人。如果记录成功,我想将重定向设置为example.com。我在课堂上有变化RedirectIfAuthenticated

public function handle($request, Closure $next)
{
    if ($this->auth->check())
    {
        return new RedirectResponse(url('/home'));
    }
    return $next($request);
}

public function handle($request, Closure $next)
{
    if ($this->auth->check())
    {
        return new RedirectResponse(url('/'));
    }
    return $next($request);
}

它仍然重定向到example.com/home

有人可以帮忙吗?

为什么不从控制器进行重定向:我相信您只想重定向用户一次,而不是在调用身份验证中间件时重定向用户。

public function postLogin()
{
    $credentials = [
        'email'    => Input::get('email'),
        'password' => Input::get('password')
    ];
    if (Auth::attempt($credentials, Input::has('remember'))) return redirect(url('/home'));
}