auth.php文件具有以下代码
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'passport',
'provider' => 'users',
],
'apidriver' => [
'driver' => 'passport',
'provider' => 'drivers',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'drivers' => [
'driver' => 'eloquent',
'model' => App\Models\Driver::class,
],
],
这是驱动程序的身份验证代码
if (Auth::guard('apidriver')->attempt(['email'=>request('email'),
'password'=>request('password')])) {
$driver=Auth::guard('apidriver')->user();
$success['token'] = $driver->createToken('Pizza App')->accessToken;
return response()->json(['success' => $success], $this->successStatus);
}else{
return response()->json(['errorrr'=>'Unauthorised'], 401);
}
访问
时会产生以下错误调用未定义的方法Illuminate \ Auth \ RequestGuard :: attempt()
用户身份验证代码正常工作时
答案 0 :(得分:0)
您没有正确解析您的请求参数,
替换这一行
if(Auth::guard('apidriver')>attempt(['email'=>request('email'),'password'=>request('password')]))
用这个:
if (Auth::guard('apidriver')->attempt(['email'=>request('email'),'password'=>request('password')]))
同时检查您是否在课程顶部拨打了Illuminate\Http\Request;
。