P粉6383439952023-07-31 09:03:30
To get the token, you need to add the ->get() function.
The correct code is:
$tokens = $user->tokens()->get();
This is because $user->tokens() returns a query builder object, so you can append all the query builder functions to filter, sort and select tokens.
For example:
$user->tokens()->orderBy('created_at', 'DESC')->first();
Please note that the tokens are stored in the personal_access_tokens table and the foreign key is tokenable_id.