2017-01-16 33 views
0

我想使用laravel預期的功能。 我做了什麼是當用戶登錄到預期的網址,如果用戶沒有註冊,那麼它會去註冊其他登錄頁面。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)); 
} 

回答

0

存儲會話中的前一個URL代替,用這個;

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

如果您使用的是laravel的AUTH,則此功能開箱即用。 對於自定義身份驗證,請在您的中間件的處理方法中使用此方法;

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

看到laravel documentation創建中間件