使用 Laravel 护照与守卫客户创建 api

我想使用passport来创建带有guard客户的api。 首先当使用守卫用户返回令牌 => // true 但我想使用警卫客户。 // 我的变化 首先在'auth.php'

enter image description here

'guards' => [
            'web' => [
                'driver' => 'session','provider' => 'users',],'api' => [
                'driver' => 'passport','provider' => 'customers','hash' => false,'customer' => [
                'driver' => 'session',]
        ],'providers' => [
            'users' => [
                'driver' => 'eloquent','model' => App\Models\User::class,'customers' => [
                'driver' => 'eloquent','model' => App\Models\Customer::class,]
        
        ],

示范客户第二

use Laravel\Sanctum\HasApiTokens;
    
    use HasFactory,Notifiable,HasApiTokens;

方法寄存器中的第三个

enter image description here

 public function register(Request $request) {
        
        $request['password']=Hash::make($request['password']);
        $request['remember_token'] = Str::random(10);
        $customer = Customer::create($request->toArray());
        $token = $customer->createToken('Laravel Password Grant Client')->accessToken;
        
        $response = ['token' => $token];
        return response($response,200);
    } 

final in database table oauth clients in column provider data in users 尝试将其更改为与客户相同的结果 客户创建后数据返回

{
        "status": 1,"data": {
            "token": {
                "name": "Laravel Password Grant Client","abilities": [
                "*"
                ],"tokenable_id": 48,"tokenable_type": "App\\Models\\Customer","updated_at": "2021-08-01T13:44:41.000000Z","created_at": "2021-08-01T13:44:41.000000Z","id": 47
            }
        },"message": "success"
    }

enter image description here

linwanping 回答:使用 Laravel 护照与守卫客户创建 api

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/1649.html

大家都在问