Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
何时在Laravel 5 auth trait中设置重定向路径属性_Laravel_Laravel 5 - Fatal编程技术网

何时在Laravel 5 auth trait中设置重定向路径属性

何时在Laravel 5 auth trait中设置重定向路径属性,laravel,laravel-5,Laravel,Laravel 5,在Laravel的默认AuthController类使用的AuthenticatesAndRegistersUsers特征中,使用以下代码: return redirect()->intended($this->redirectPath()); redirectPath()函数如下所示: public function redirectPath() { if (property_exists($this, 'redirectPath')) { ret

在Laravel的默认
AuthController
类使用的
AuthenticatesAndRegistersUsers
特征中,使用以下代码:

return redirect()->intended($this->redirectPath());
redirectPath()
函数如下所示:

public function redirectPath()
{
    if (property_exists($this, 'redirectPath'))
    {
        return $this->redirectPath;
    }
    return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home';
}
阅读此代码时,我可以在
AuthController
类上设置两个不同的属性:
redirectPath
redirectTo
<代码>重定向路径优先于
重定向到


当我想将默认页面从
/home
重定向到
/
时,我认为最好设置
重定向到
属性。
redirectPath
属性的预期用途是什么?

我认为,既然
authenticates和registersusers
是一种特性,可以由不同的类使用,两个属性检查都是为了与不同的类向后兼容,但逻辑具有相同的目的


通常我建议您使用
重定向路径
属性,因为这是该函数中的第一个条件,如果出于任何原因,您没有注意并使用控制器中的
重定向到
属性,该属性扩展了另一个定义了
重定向路径的控制器,那么您最终将思考出了什么问题,以及为什么控制器将您重定向到不同的路径。

我找到了一些问题这些属性和
重定向路径()函数的历史记录

2014年11月30日 重定向最初是在
AuthenticatesAndRegistersUsers
trait中硬编码的。

+返回重定向('/home');
重定向已更改为
redirect($this->redirectTo)

-返回重定向('/home');
+返回重定向($this->redirectTo);
2014年12月1日 添加了重定向路径()
函数

+公共函数重定向路径()
+    {
+返回属性_存在($this,'redirectTo')?$this->redirectTo:'/home';
+    }
并将重定向更改为
redirect($this->redirectPath())

-返回重定向($this->redirectTo);
+返回重定向($this->redirectPath());
同时,删除了
AuthController
中的属性

-protected$redirectTo='/home';
2015年2月7日
redirectPath
属性已添加到
redirectPath()
函数:

公共函数重定向路径()
{
+如果(属性_存在($this,'redirectPath'))
+        {
+返回$this->redirectPath;
+        }
返回属性_存在($this,'redirectTo')?$this->redirectTo:'/home';
}
结论
看起来要使用的正确属性是
redirectPath
,因为它与
redirectPath()
函数一致。它还设计用于覆盖可能已添加的任何较旧的
重定向到
属性。

它看起来不像
AuthController
类在默认情况下设置了
重定向路径
属性(他们曾设置过
重定向到
属性)。其他一切似乎都是对的,所以我把它标为公认的答案。请参阅我的答案,了解我挖掘的更多细节。啊,对不起,也许你是对的。我在我的一个项目上查看了
AuthController
,但似乎默认情况下该属性不在那里,我已经手动添加了它。很抱歉,我将编辑我的答案。很好…*掌声*