Installation
Laravel Breeze API provides a minimal authentication implementation for Laravel applications that serve as the backend for Next.js frontends.Requirements
- PHP 8.2 or higher
- Composer
- MySQL, PostgreSQL, or SQLite database
Install Dependencies
Environment Configuration
Copy the example environment file and configure your application:Application Settings
.env
Database Configuration
Configure your database connection:.env
Session Configuration
For API authentication with Sanctum, configure database sessions:.env
Mail Configuration
Configure mail settings for password reset and email verification:.env
Cache and Queue
.env
Laravel Sanctum Configuration
Sanctum provides the authentication layer for your API. Configure stateful domains for cookie-based authentication.Stateful Domains
Editconfig/sanctum.php to allow your frontend domain:
config/sanctum.php
.env:
.env
Authentication Guards
config/sanctum.php
Token Configuration
config/sanctum.php
Middleware Configuration
config/sanctum.php
CORS Configuration
Configure Cross-Origin Resource Sharing to allow requests from your Next.js frontend.config/cors.php
The
supports_credentials option must be true to allow cookie-based authentication.Database Setup
Generate your application key and run migrations:Running the Application
Development Server
Start the Laravel development server:http://localhost:8000.
With Queue Worker
Run the application with queue processing:- Laravel development server on port 8000
- Queue worker for background jobs
- Vite development server for asset compilation
Automated Setup
Use the automated setup script:- Install composer dependencies
- Copy
.env.exampleto.envif it doesn’t exist - Generate application key
- Run database migrations
- Install and build npm dependencies
Verification
Test that your API is running correctly:Next Steps
API Routes
Learn about available API endpoints
Controllers
Understand controller structure
Database
Explore migrations and models
Testing
Set up and run tests