Laravel Sanctum provides a simple token-based authentication system for SPAs and simple API services. Learn how to set up Sanctum for API authentication.
- Install Laravel Sanctum:
- Run
composer require laravel/sanctum
and follow the installation instructions.
- Run
- Publish Sanctum Configuration:
- Run
php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider"
- Run
- Set Up Sanctum Middleware:
- Add
Sanctum::middleware('auth:sanctum')
to your API middleware group inapp/Http/Kernel.php
.
- Add
Using Laravel Sanctum allows you to implement a simple and effective authentication system for APIs and SPAs.