Php Symfony\Component\Debug\Exception\FatalThrowableError:传递参数2以照亮\Auth\SessionGuard::\uu构造()
我正在尝试为两个表实现LaravelPassport,所以一个是默认用户,第二个是设备。 我在配置中为新模型创建了Guard,如果我尝试注册设备,它会写入设备表,但现在如果我尝试登录,它会出现以下错误:Php Symfony\Component\Debug\Exception\FatalThrowableError:传递参数2以照亮\Auth\SessionGuard::\uu构造(),php,laravel,Php,Laravel,我正在尝试为两个表实现LaravelPassport,所以一个是默认用户,第二个是设备。 我在配置中为新模型创建了Guard,如果我尝试注册设备,它会写入设备表,但现在如果我尝试登录,它会出现以下错误: Symfony\Component\Debug\Exception\FatalThrowableError: Argument 2 passed to Illuminate\Auth\SessionGuard::__construct() must implement interface Il
Symfony\Component\Debug\Exception\FatalThrowableError: Argument 2 passed to Illuminate\Auth\SessionGuard::__construct() must implement interface Illuminate\Contracts\Auth\UserProvider, null given, called in /Users/petarceho/laravel/api/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php on line 127 in file /Users/petarceho/laravel/api/vendor/laravel/framework/src/Illuminate/Auth/SessionGuard.php on line 99
我是新来拉威尔的,很抱歉不能解释清楚,但我可以用拉威尔护照坐两张桌子吗
以下是我的设备控制器类:
<?php
namespace App\Http\Controllers;
use App\Device;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class DeviceController extends Controller{
//register
public function signupDevice(Request $request)
{
//cant registed with the same email twice
if(sizeof(Device::where('name','=',$request->query('name'))->get()) > 0)
return response()->json(['name has already been taken'],500);
$request->validate([
'name' => 'required|string',
'password' => 'required|string|confirmed']);
$device =new Device(
[
'name'=>$request->name,
'password'=>bcrypt($request->password)
]);
$device->save();
return response()->json([
'message' => 'Successfully created device!'
], 201);
}
public function login(Request $request)
{
if (Auth::guard('device')->attempt(['name' => request(['name']), 'password' => request(['password'])])) {
$details = Auth::guard('device')->user();
$user = $details['original'];
return $user;}
else {return 'auth fail';}
}
public function login1(Request $request){
//validate the data input
$request->validate([
'name' => 'required|string', // |string|name
'password' => 'required|string',
// 'remember_me' => 'boolean'
]);
$credentials = request(['name', 'password']);
if(!Auth::attempt($credentials))
return response()->json([
'message' => 'Unauthorized'
], 401);
$device = $request->user('device');
// $device = Auth::guard('device')->device();
$tokenResult = $device->createToken('Personal Access Token');
$token = $tokenResult->token;
if ($request->remember_me)
$token->expires_at = Carbon::now()->addWeeks(1);
$token->save();
return response()->json([
'access_token' => $tokenResult->accessToken,
'token_type' => 'Bearer',
'expires_at' => Carbon::parse(
$tokenResult->token->expires_at
)->toDateTimeString()
],200);
}
}
我的路线是:
//routes for device auth
Route::group(
[
'prefix'=>'auth/device'
],function ()
{
Route::post('signup','DeviceController@signupDevice');
Route::post('login','DeviceController@login');
});
应用程序/设备类
Lightlight\Foundation\Auth\设备看起来与用户类完全相同
<?php
namespace App;
use Illuminate\Foundation\Auth\Device as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Passport\HasApiTokens;
class Device extends Authenticatable{
use Notifiable;//,HasApiTokens;
protected $table ='device';
protected $fillable = [
'name', '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',
];
}
请编辑问题并添加App\Device
模型关于您的上一个问题:在我遇到类似问题之前,没有任何帮助,因此我使用了JWT,您应该可以获得带有该配置的ElountituserProvider
。你试过运行php artisan config:clear
?Adam解决了这个问题,我现在得到了不同的错误,但是这个错误被清除了,谢谢!请编辑该问题并添加App\Device
模型关于您的上一个问题:在我遇到类似问题之前,没有任何帮助,因此我使用了JWT,您应该获得带有该配置的EloquentUserProvider
。你试过运行php artisan config:clear
?Adam解决了这个问题,我现在得到了不同的错误,但是这个错误被清除了,谢谢!
<?php
namespace App;
use Illuminate\Foundation\Auth\Device as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Passport\HasApiTokens;
class Device extends Authenticatable{
use Notifiable;//,HasApiTokens;
protected $table ='device';
protected $fillable = [
'name', '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',
];
}