oquentUserProvider覆盖validateCred

oquentUserProvider覆盖validateCred

本文介绍了Laravel 5.4 EloquentUserProvider覆盖validateCredentials的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public function validateCredentials(UserContract $user, array $credentials)
    {
        $plain = $credentials['password'];

        return $this->hasher->check($plain, $user->getAuthPassword());
    }

如何在类EloquentUserProvider中重写方法validateCredentials?谢谢!

How to override a method validateCredentials in the class EloquentUserProvider?? Thanks!

推荐答案

您可以创建自己的UserProvider,然后可以覆盖原始UserProvider中的功能.

You can create your own UserProvider and then you can override the functions from the original UserProvider.

首先,您创建CustomUserProvider:

First you create the CustomUserProvider:

use Illuminate\Contracts\Auth\UserProvider;
use Illuminate\Contracts\Auth\Authenticatable as UserContract;

class CustomUserProvider extends UserProvider {

  public function validateCredentials(UserContract $user, array $credentials)
  {
    $plain = $credentials['password'];

    return $this->hasher->check($plain, $user->getAuthPassword());
  }

}

然后,您在config/app.php中注册新的CustomUserProvider

Then you register your new CustomUserProvider in config/app.php

'providers' => array(
   ... On the bottom, must be down to override the default UserProvider
   'Your\Namespace\CustomUserProvider'
),

这篇关于Laravel 5.4 EloquentUserProvider覆盖validateCredentials的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 05:17