To implement authentication in Laravel 12 and later versions using Sanctum, follow these steps:
Laravel Sanctum uses session-based authentication for routes defined in web.php. This works out of the box if you're already using the default Laravel authentication system (e.g., login via form, CSRF protection, etc.).
For API routes, Sanctum expects token-based authentication. To access these routes:
First, generate a token for the user:
$token = $user->createToken('api-token')->plainTextToken;
Then, in your API requests, include the token in the Authorization header like this:
Authorization: Bearer <your-token-here>
This token is stored in the personal_access_tokens
table and is used to authenticate API requests.
you can follow this Stackoverflow thread.