php - 如何在 Laravel 中覆盖 auth 登录功能

标签 php laravel laravel-5

我需要覆盖 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 内部实现,我相信我真的应该重写它的这个函数。

我在哪里可以找到它的实现?

最佳答案

我建议不要覆盖任何函数,而是创建一个新的 guardprovider。查看 config/auth.php 以了解它们是如何定义的。

然后您可以将自定义保护设置为默认值,然后正常的身份验证流程将接管。

请参阅 Adding Custom Guards 上的文档

关于php - 如何在 Laravel 中覆盖 auth 登录功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51050523/

相关文章:

php - 如何放宽 PHP 的 open_basedir 限制?

php - 使用 PHP Curl 发布数据并检索响应?

Laravel mongodb 事务不回滚

php - 找不到 Laravel Class Socialite

php - Laravel-5 'LIKE' 等效( Eloquent )

php - 如何处理大量数据以获得良好的性能?

php - mysql_real_escape_string - 登录脚本

php - Laravel 在不同环境下的细微差别

php - 连接到 CommissionJunction token 时出错 : [60] SSL certificate problem: unable to get local issuer certificate

php - laravel 5 可以 GET 路由,但不能 POST