我如何能够在laravel中使用模型进行验证

时间:2018-02-20 21:19:45

标签: php laravel authentication

Person
    id - integer
    dni - string
    name - string
User
    id-interger
    id_person integer
    password-string

我有这两个表,我需要使用来自用户的dni和来自用户

的密码进行身份验证

我尝试添加

  public function username()
    {
        return 'dni';
    }
在Auth / LoginController中

,但无法正常工作 在我的config / auth.php中:

'users' => [
            'driver' => 'eloquent',
            'model' => App\User::class,
        ],

我怎样才能使用两个不同的表字段进行身份验证?

1 个答案:

答案 0 :(得分:0)

你可以做到

$person = Person::where('dni', $dni)->first();

if (Auth::attempt(['id_person' => $person->id, 'password' => $password])) {

     // Authentication passed...
}