在为我的laravel 5.2创建自定义认证时,我遇到了错误,然而这段代码在我的laravel 5.1上运行良好。我的config/auth.php文件:
'providers' => [
'users' => [
'driver' => 'custom',
'model' => App\User::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
我的CustomUserProvider.php(Auth / CustomUserProvider)文件
<?php namespace App\Auth;
use Illuminate\Contracts\Auth\UserProvider;
use Illuminate\Contracts\Hashing\Hasher as HasherContract;
use Illuminate\Contracts\Auth\Authenticatable as UserContract;
class CustomUserProvider implements UserProvider {
protected $model;
public function __construct(UserContract $model)
{
$this->model = $model;
}
public function retrieveById($identifier)
{
}
public function retrieveByToken($identifier, $token)
{
}
public function updateRememberToken(UserContract $user, $token)
{
}
public function retrieveByCredentials(array $credentials)
{
}
public function validateCredentials(UserContract $user, array $credentials)
{
}
}
我的CustomAuthProvider.php文件
<?php namespace App\Providers;
use App\User;
use Auth;
use App\Auth\CustomUserProvider;
use Illuminate\Support\ServiceProvider;
class CustomAuthProvider extends ServiceProvider {
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
$this->app['auth']->extend('custom',function()
{
return new CustomUserProvider();
});
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
//
}
}
在Laravel 5.1中,这个功能运行良好,在5.2版本中出现了错误。
InvalidArgumentException in CreatesUserProviders.php line 40:
Authentication user provider [custom] is not defined.
'driver' => 'custom'
更改为'driver' => 'customUser'
,并将$this->app['auth']->extend('custom',function()
更改为$this->app['auth']->extend('customUser',function()
。 - Alankar More