J'ai une application dans laquelle j'ai créé une nouvelle garde appelée residents
qui est la copie exacte de l'option par défaut User
qui est fournie avec le logiciel laravel. Mais lorsque je modifie la garde, il commence à afficher cette erreur :Argument 2 passed to Illuminate\Auth\SessionGuard::__construct() must be an instance of Illuminate\Contracts\Auth\UserProvider, null given, called in ...\vendor\laravel\framework\src\Illuminate\Auth\AuthManager.php on line 125
J'ai cherché la solution sur Google et j'en ai lu beaucoup, mais rien n'a fonctionné.
La version de Laravel est 5.8
auth.php
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'residents',
'hash' => false,
],
],
'providers' => [
'residents' => [
'driver' => 'eloquent',
'model' => App\ApiModels\Resident::class,
],
],
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
],
],
Application \ApiModels\Resident.php
namespace App\ApiModels;
use \Illuminate\Notifications\Notifiable;
use \Illuminate\Contracts\Auth\MustVerifyEmail;
use \Illuminate\Foundation\Auth\User as Authenticatable;
class Resident extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
/**
* Authenticate the user
*
* @param object $request
* @return array
*/
public function _login($request)
{
if(\Auth::attempt([
'email' => $request->email,
'password' => $request->password
]))
{
return [
'success' => true
];
}
else
{
return [
'success' => false
];
}
}
}
itinéraire \api.php
Route::get('/login', 'Api\ResidentsController@login');
Api \ResidentsController.php
namespace App\Http\Controllers\Api;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
/**
* Models
*/
use App\ApiModels\Resident;
class ResidentsController extends Controller
{
public function __construct()
{
/**
* Middleware(s)
*/
$this->middleware('auth:api', [
'except' => [
'login',
'logout'
]
]);
}
public function login(Request $request)
{
...
return response()->json([
'login_id' => $request->login_id,
'password' => $request->password
]);
}
}