继承 EloquentUserProvider
<?php
namespace App\Providers;
use Illuminate\Auth\EloquentUserProvider;
use Illuminate\Contracts\Auth\ Authenticatable as UserContract;
class ApiEloquentUserProvider extends EloquentUserProvider
{
public function validateCredentials( UserContract $user, array $credentials)
{
//这里写自己的验证规则
$password = $user->system_encrypt($credentials['password'],$user['salt']);
return $password == $user->getAuthPassword();
}
}
修改App\Providers\AuthServiceProvider
public function boot()
{
$this->registerPolicies();
Auth::provider('api-eloquent', function ( $app, array $config) {
return new \App\Providers\ApiEloquentUserProvider( $app[ 'hash'], $config[ 'model']);
});
}
然后就可以在config/auth.php里直接使用了
‘driver’ => ‘api-eloquent’,