gpt4 book ai didi

laravel - 何时在 Laravel 5 auth 特征中设置 redirectPath 属性

转载 作者:行者123 更新时间:2023-12-01 20:15:38 26 4
gpt4 key购买 nike

在 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 类上设置两个不同的属性:redirectPathredirectToredirectPath 优先于 redirectTo

当我想要更改默认页面以从 /home 重定向到 / 时,我认为最好设置 redirectTo属性(property)。 redirectPath 属性的预期用途是什么?

最佳答案

我挖掘了这些属性和 redirectPath() 的一些历史记录。功能。

2014 年 11 月 30 日

重定向最初硬编码在 AuthenticatesAndRegistersUsers 中特征。 https://github.com/laravel/framework/commit/cc1c35069a7bbc3717487d931fbd80b8e6641a90

+    return redirect('/home');

重定向已更改为 redirect($this->redirectTo) https://github.com/laravel/framework/commit/a71926653a573f32ca7a31527c7644c4305c1964#diff-b72935cc9bfd1d3e8139fd163ae00bf5

-    return redirect('/home');
+ return redirect($this->redirectTo);

2014 年 12 月 1 日

redirectPath()添加了功能 https://github.com/laravel/framework/commit/dd78c4fe763859d11e726477125b7d1a00c860c0#diff-b72935cc9bfd1d3e8139fd163ae00bf5

+    public function redirectPath()
+ {
+ return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home';
+ }

重定向更改为 redirect($this->redirectPath())

-    return redirect($this->redirectTo);
+ return redirect($this->redirectPath());

同时,AuthController中的属性被删除 https://github.com/laravel/laravel/commit/57a6e1ce7260444719dd3de1fdd7c58cdcdba362

-    protected $redirectTo = '/home';

2015 年 2 月 7 日

redirectPath属性已添加到 redirectPath()功能: https://github.com/laravel/framework/commit/63a534a31129be4cec4f5a694342d7020e2d7f07#diff-b72935cc9bfd1d3e8139fd163ae00bf5

     public function redirectPath()
{
+ if (property_exists($this, 'redirectPath'))
+ {
+ return $this->redirectPath;
+ }
return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home';
}

结论

看起来要使用的正确属性是 redirectPath因为它与 redirectPath() 一致功能。它还旨在覆盖任何旧的 redirectTo可能已添加的属性。

关于laravel - 何时在 Laravel 5 auth 特征中设置 redirectPath 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30425208/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com