在Laravel 5.4,你不需要註冊CustomUserProvider在config/app.php。
首先,在你提供商創建CustomUserProvider.php文件目錄:
<?php
namespace App\Providers;
use Illuminate\Auth\EloquentUserProvider as 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());
}
}
在此之後,在你的AuthServiceProvider.php文件改變boot()
方法:
public function boot()
{
$this->registerPolicies();
\Illuminate\Support\Facades\Auth::provider('customuserprovider', function($app, array $config) {
return new CustomUserProvider($app['hash'], $config['model']);
});
}
現在,您可以通過將驅動程序名稱添加到您的config/a中來使用該提供程序uth.php file:
'providers' => [
'users' => [
'driver' => 'customuserprovider',
'model' => App\User::class,
'table' => 'users',
],
],