我目前很困惑为什么我的令牌响应 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)