注册

时间:2017-01-16 07:57:31

标签: laravel laravel-5.3

我想使用laravel预期的功能。 我所做的是当用户登录它到达目标网址时,如果用户没有注册,那么它将进入注册其他登录页面。

我无法理解我做错了什么

以下是我的 LoginController

public function showLoginForm()
{
    if(!session()->has('from')){
        session()->put('from', url()->previous());
    }
    return view('auth.login');
}

public function authenticated($request,$user)
{
    return redirect(session()->pull('from',$this->redirectTo));
} 

1 个答案:

答案 0 :(得分:0)

Instead of storing the previous url in a session, use this;

return redirect()->guest('/your-login-route');
//this stores your intended route and redirects if not authenticated

If you are using laravel's AUTH this feature is provided out of the box. For custom authentication, use this in your middleware's handle method like this;

public function handle($request, Closure $next, $guard = 'custom-guard')
{
    if(! Auth::guard($guard)->check()){
        return redirect()->guest('/your-login-route');
    }
    return $next($request);
}

see laravel documentation to create a middleware