2017-08-14 126 views
0

使用Laravel 5.4我正在使用內置身份驗證過程。

我要動態地改變這樣的:

/** 
* URI where we redirect to after registration 
* 
* @var string 
*/ 
protected $redirectTo = 'player/home'; 

像這樣:

/** 
* The "booting" method of the model. 
*/ 
protected static function boot() 
{ 
    if (session()->has('game.details.redirect')) { 
     $this->redirectTo = session()->get('game.details.redirect'); 
    } 
} 

但上面的,因爲我不能在靜態方法來訪問$this不起作用。每次訪問控制器時,我如何實現這個任務?

回答

2

您可以定義功能redirectTo而不是loginController中的屬性。

由於Laravel醫生說:

如果重定向路徑需要定製生成邏輯,你可以定義一個redirectTo方法,而不是redirectTo財產

function redirectTo(){ 
     if (session()->has('game.details.redirect')) { 
      return session()->get('game.details.redirect'); 
     } 
    } 

而且,它也是更首選方法。

redirectTo方法將優先於redirectTo屬性。

瞭解更多關於在這裏:​​Laravel Authentication

希望這回答了你的問題。