【问题标题】:Using custom id (api_account_id) instead of conventional user_id problem on laravel passport在 laravel 护照上使用自定义 id (api_account_id) 而不是常规的 user_id 问题
【发布时间】:2021-07-23 03:32:23
【问题描述】:

我目前无法设置 Laravel Passport。就我而言,我没有使用 User 作为我的模型。相反,我有 ApiAccount。因此,当 laravel 护照添加 OAuth 迁移时,我将所有提及的 user_id 更改为 api_account_id。现在我无法通过运行php artisan passport:install 添加个人访问客户端。错误说他们找不到 user_id 列。这个问题有解决办法吗?

错误

SQLSTATE[42S22]:找不到列:1054 未知列 'user_id' 在 '字段列表' (SQL: 插入oauth_clients (user_id, name, secret, redirect, personal_access_client, password_client, revoked, updated_at, created_at)

OAuth 迁移

public function up()
{
    Schema::create('oauth_clients', function (Blueprint $table) {
        $table->increments('id');
        $table->bigInteger('api_account_id')->index()->nullable();
        $table->string('name');
        $table->string('secret', 100);
        $table->text('redirect');
        $table->boolean('personal_access_client');
        $table->boolean('password_client');
        $table->boolean('revoked');
        $table->timestamps();
    });
}

ApiAccount 模型

class ApiAccount extends Authenticatable
{
    use SoftDeletes;

    use Notifiable, HasApiTokens;

auth.php

    'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],

    'api' => [
        'driver' => 'passport',
        'provider' => 'api_accounts',
        'hash' => false,
    ],
],

'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model' => App\Partner::class,
    ],
    'api_accounts' => [
        'driver' => 'eloquent',
        'model' => App\ApiAccount::class,
    ],

【问题讨论】:

    标签: php laravel laravel-passport


    【解决方案1】:

    您可以查看Passport Install command 上实际发生的代码,并在您的项目中将其自定义为您自己的Artisan command

    【讨论】:

    • 这不是一个全面的答案
    猜你喜欢
    • 1970-01-01
    • 2020-04-17
    • 2021-12-03
    • 2017-12-28
    • 2017-03-29
    • 2019-05-23
    • 2019-05-08
    • 2013-06-21
    • 2017-11-25
    相关资源
    最近更新 更多