laravel passport createToken 没有给我哈希令牌
laravel passport createToken not giving me the hashed token
laravel passport createToken 没有给我哈希 token.It 从数据库 table
给我这个对象
{
"name": "Laravel Password Grant Client",
"abilities": [
"*"
],
"tokenable_id": 10,
"tokenable_type": "App\Models\User",
"updated_at": "2021-09-02T15:58:03.000000Z",
"created_at": "2021-09-02T15:58:03.000000Z",
"id": 7
}.
我需要令牌进行验证。
我做到了 composer require laravel/passport
php artisan migrate
php artisan passport:install
使用 HasApiTokens、HasFactory、Notifiable;
在AuthServiceProvider的boot方法中
Passport::routes();
在 config/auth.php
'api' => [
'driver' => 'passport',
'provider' => 'users',
],
我的注册控制器功能
$validator = Validator::make($request->all(), [
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|confirmed|string|min:6',
]);
if ($validator->fails()) {
return response(['errors' => $validator->errors()->all()], 422);
}
$request['password'] = Hash::make($request['password']);
$request['remember_token'] = Str::random(10);
$user = User::create($request->toArray());
$token = $user->createToken('Laravel Password Grant Client')->accessToken;
return response(["ok" => true, "message" => "You have successfully registered", "user" => $user, "token" => $token], 200);
那只是 laravel 默认给我 sanctum。并且用户模型中的 HasApiToken 默认来自 sanctum 而不是 passport.
请确保您使用的特征正确
use Laravel\Passport\HasApiTokens;
没有
use Laravel\Sanctum\HasApiTokens;
如果您使用护照作为身份验证,请确保它使用 Laravel\Passport\HasApiTokens,而不是 Laravel\Sanctum\HasApiTokens;在您的用户模型中
laravel passport createToken 没有给我哈希 token.It 从数据库 table
给我这个对象{
"name": "Laravel Password Grant Client",
"abilities": [
"*"
],
"tokenable_id": 10,
"tokenable_type": "App\Models\User",
"updated_at": "2021-09-02T15:58:03.000000Z",
"created_at": "2021-09-02T15:58:03.000000Z",
"id": 7
}.
我需要令牌进行验证。
我做到了 composer require laravel/passport
php artisan migrate
php artisan passport:install
使用 HasApiTokens、HasFactory、Notifiable; 在AuthServiceProvider的boot方法中 Passport::routes(); 在 config/auth.php
'api' => [
'driver' => 'passport',
'provider' => 'users',
],
我的注册控制器功能
$validator = Validator::make($request->all(), [
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|confirmed|string|min:6',
]);
if ($validator->fails()) {
return response(['errors' => $validator->errors()->all()], 422);
}
$request['password'] = Hash::make($request['password']);
$request['remember_token'] = Str::random(10);
$user = User::create($request->toArray());
$token = $user->createToken('Laravel Password Grant Client')->accessToken;
return response(["ok" => true, "message" => "You have successfully registered", "user" => $user, "token" => $token], 200);
那只是 laravel 默认给我 sanctum。并且用户模型中的 HasApiToken 默认来自 sanctum 而不是 passport.
请确保您使用的特征正确
use Laravel\Passport\HasApiTokens;
没有
use Laravel\Sanctum\HasApiTokens;
如果您使用护照作为身份验证,请确保它使用 Laravel\Passport\HasApiTokens,而不是 Laravel\Sanctum\HasApiTokens;在您的用户模型中