[英]Laravel 5.4 change $redirectTo value in built in log in to session value
Working with Laravel 5.4
and I am using the built in authentication process. 使用
Laravel 5.4
,我正在使用内置的身份验证过程。
I want to change this dynamically: 我想动态地改变它:
/**
* URI where we redirect to after registration
*
* @var string
*/
protected $redirectTo = 'player/home';
Like this: 像这样:
/**
* The "booting" method of the model.
*/
protected static function boot()
{
if (session()->has('game.details.redirect')) {
$this->redirectTo = session()->get('game.details.redirect');
}
}
But the above does not work as I cannot access $this
in static method. 但是上述方法不起作用,因为我无法以静态方法访问
$this
。 How do I achieve this assignment every time the controller is accessed? 每次访问控制器时如何实现此分配?
You can define the function redirectTo
instead of the property in loginController
. 您可以定义函数
redirectTo
而不是loginController
中的属性。
As Laravel doc says: 正如Laravel博士所说:
If the redirect path needs custom generation logic you may define a redirectTo method instead of a redirectTo property
如果重定向路径需要自定义生成逻辑,则可以定义redirectTo方法而不是redirectTo属性
function redirectTo(){
if (session()->has('game.details.redirect')) {
return session()->get('game.details.redirect');
}
}
And, it is also the more preferred method. 并且,它也是更优选的方法。
The redirectTo method will take precedence over the redirectTo attribute.
redirectTo方法将优先于redirectTo属性。
Read more about it here : Laravel Authentication 在此处了解更多信息: Laravel身份验证
Hope it answers your question. 希望它能回答您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.