在Laravel 5.0中,trait AuthenticatesAndRegistersUsers 中的 redirectPath 方法检查属性 redirectPath 或 redirectTo 是否存在。如果是这样,用户将被重定向到该路径。
问题是,它设置在哪里?我知道它设置为用户在被重定向到/auth/login 页面之前尝试加载的页面。但是,我不知道这是在哪里设置的。
public function redirectPath()
{
if (property_exists($this, 'redirectPath'))
{
return $this->redirectPath;
}
return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home';
}
默认情况下,
它根本没有设置!!这就是为什么该函数需要用 property_exists()
检查它的原因。您可以在任何导入特征的位置设置它 use AuthenticatesAndRegistersUsers
.
在默认的Laravel安装中,这将是AuthController
:
class AuthController extends Controller {
use AuthenticatesAndRegistersUsers;
protected $redirectTo = '/foo/bar';
// ...
}
在特质中:
Illuminate''Foundation''Auth''RedirectsUsers.php