![](/img/trans.png)
[英]How can I get user_id with access token in laravel passport api?
[英]Using custom id (api_account_id) instead of conventional user_id problem on laravel passport
我目前在设置 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();
});
}
api账户模型
class ApiAccount extends Authenticatable
{
use SoftDeletes;
use Notifiable, HasApiTokens;
身份验证文件
'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,
],
您可以查看Passport Install 命令实际发生的代码,并将其自定义为您项目中自己的Artisan 命令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.