Laravel Passport列\"api_token \"不存在 [英] Laravel Passport column \"api_token\" does not exist
问题描述
我正在为api项目设置laravel护照.我尝试按照此网站上的步骤进行操作但无法通过身份验证.
I am setting up laravel passport on a api project. I try to follow the steps on this site but couldn't get the authenication to work.
请求令牌部分似乎正常.呼叫 http://127.0.0.1:8000/oauth/token 时,它会返回有效令牌.
The requesting a token part seems to work fine. When making a call to http://127.0.0.1:8000/oauth/token, it return a valid token.
当我使用授权标头中的令牌向api发送请求时,它给出一列"api_token"不会退出错误
When I send a request to the api with the token in the Authorization Header, it gives a column "api_token" does not exit error
Authorization Header: Authorization:Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1Ni........
错误:
"SQLSTATE[42703]: Undefined column: 7 ERROR: column "api_token" does not exist↵LINE 1: select * from "users" where "api_token" = $1 limit 1↵
我需要自己创建api_token列吗?我使用默认的迁移文件来创建表.这是用户表的迁移文件
Do I need to create the api_token column myself? I used the default migration file to create the table. This is the migration file for the users table
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
推荐答案
以此更改config/auth.php文件的guards
.
Change guards
of config/auth.php file with this.
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'passport',
'provider' => 'users',
'hash' => true,
],
],
更改auth.php后,清除所有缓存.
after changing auth.php, clear all cache.
这篇关于Laravel Passport列\"api_token \"不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!