Complete the code to generate a new API token for the authenticated user.
$token = auth()->user()->[1]('api-token');
The createToken method generates a new API token for the user in Laravel.
Complete the code to revoke the current user's token.
auth()->user()->currentAccessToken()->[1]();The delete method removes the current access token from the database, effectively revoking it.
Fix the error in the code to check if the token has a specific ability.
if ($token->[1]('update-posts')) { // allow update }
The can method checks if the token has a given ability in Laravel Sanctum.
Fill both blanks to create a token with specific abilities and retrieve its plain text token.
$token = auth()->user()->[1]('api-token', ['create', 'update']); $plainTextToken = $token->[2];
createToken creates a token with abilities, and plainTextToken gets the token string to send to clients.
Fill all three blanks to revoke all tokens except the current one for the authenticated user.
auth()->user()->tokens()->where('id', '!=', auth()->user()->[1]()->id)->[2](); $currentToken = auth()->user()->[3]();
This code deletes all tokens except the current one by comparing token IDs, then retrieves the current token.