小编Jad*_*ade的帖子

Laravel Passport Token 不返回一系列代码

我目前很困惑为什么我的令牌响应 JSON 不提供令牌代码。

"token": {
    "token": {
        "name": "appToken",
        "abilities": [
            "*"
        ],
        "tokenable_id": 1,
        "tokenable_type": "App\\Models\\User",
        "updated_at": "2021-08-29T17:35:00.000000Z",
        "created_at": "2021-08-29T17:35:00.000000Z",
        "id": 7
    }
},
Run Code Online (Sandbox Code Playgroud)

这是响应的代码。

public function login()
{
    if (Auth::attempt(['email' => request('email'), 'password' => request('password')])) {
        $user = Auth::user();
        $success['token'] = $user->createToken('appToken')->accessToken;
       //After successfull authentication, notice how I return json parameters
        return response()->json([
          'success' => true,
          'token' => $success,
          'user' => $user
      ]);
    } else {
   //if authentication is unsuccessfull, notice how I return json parameters
      return response()->json([ …
Run Code Online (Sandbox Code Playgroud)

token laravel laravel-passport

3
推荐指数
1
解决办法
1433
查看次数

标签 统计

laravel ×1

laravel-passport ×1

token ×1