我需要覆盖 laravel 的默认登录功能,但是我对在那里找到的代码感到困惑。我不明白 laravel AuthenticatesUsers.php 如何验证用户存在于数据库中,然后对用户进行身份验证。
我在AuthenticatesUsers.php
中使用了这个函数/**
* Attempt to log the user into the application.
*
* @param \Illuminate\Http\Request $request
* @return bool
*/
protected function attemptLogin(Request $request)
{
return $this->guard()->attempt(
$this->credentials($request), $request->filled('remember')
);
}
我想我需要在 auth/LoginController.php 中覆盖这个函数
但我不明白它是如何工作的。 guard()
和 attempt()
在哪里实现,我想真正的行动发生在那里。我需要为登录添加另一个条件。
有人了解 laravel 的默认登录是如何工作的吗?以及这两个函数 guard()
和 attempt()
,例如 attempt 并没有在 AuthenticatesUsers.php 内部实现,我相信我真的应该重写它的这个函数。
我在哪里可以找到它的实现?
最佳答案
我建议不要覆盖任何函数,而是创建一个新的 guard
和 provider
。查看 config/auth.php
以了解它们是如何定义的。
然后您可以将自定义保护设置为默认值,然后正常的身份验证流程将接管。
请参阅 Adding Custom Guards 上的文档
关于php - 如何在 Laravel 中覆盖 auth 登录功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51050523/