Laravelに付属のデフォルトresidents
クラスの正確なコピーであるUser
という新しいガードを作成したアプリケーションがあります。しかし、このエラーを表示しているガードを変更したとき: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
私は解決策のためにグーグルを試してみました、そして多くの人は何もうまくいかなかった。
Laravelのバージョンは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,
],
],
_
app\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',
];
/**
* @Author : Parminder Singh
* @Last modified : 09, August 2019
*
* @Function name : _login
* @Description : Function to authenticate the user
* @Parameters : $request as $object
*
* @Method :
* @Returns : raw data
* @Return type : array
*/
public function _login($request)
{
if(\Auth::attempt([
'email' => $request->email,
'password' => $request->password
]))
{
return [
'success' => true
];
}
else
{
return [
'success' => false
];
}
}
}
_
route\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
]);
}
}
_
問題はconfig/auth.php
で発生します。 web
guardは、users
配列で宣言されていないproviders
プロバイダを使用しています。これを修正するための2つのオプションがあります(1つ選択)。
users
プロバイダを追加しますweb
Guardを使用しない場合は、代わりにデフォルトガードをapi
にしてください。'defaults' => [
'guard' => 'api',
'passwords' => 'residents',
],
'guards' => [
'api' => [
'driver' => 'token',
'provider' => 'residents',
'hash' => false,
],
],
'providers' => [
'residents' => [
'driver' => 'eloquent',
'model' => App\ApiModels\Resident::class,
],
],
'passwords' => [
'residents' => [
'provider' => 'residents',
'table' => 'password_resets',
'expire' => 60,
],
],