Laravel 12 Authentication Tutorial: In this guide, we will implement authentication in Laravel 12 using Breeze and Sanctum. Authentication is a core feature of modern web applications, allowing users to securely register, login, and access protected resources.
Laravel Breeze provides a simple authentication system for web applications, while Sanctum is used for API authentication.
Step 1. Install Laravel 12
composer create-project laravel/laravel laravel-auth cd laravel-auth
Step 2. Install Laravel Breeze
composer require laravel/breeze --dev php artisan breeze:install npm install && npm run dev php artisan migrate
Breeze provides login, registration, password reset, and email verification features.
Step 3. Test Authentication
Run the server:
php artisan serve
Visit:
- /register
- /login
Step 4. Install Laravel Sanctum
composer require laravel/sanctum php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider" php artisan migrate
Step 5. Configure Sanctum
Add Sanctum middleware in app/Http/Kernel.php:
'api' => [
\Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
],
Step 6. Create API Login
Route::post('/login', function (Request $request) {
$credentials = $request->only('email', 'password');
if (!Auth::attempt($credentials)) {
return response()->json(['message' => 'Invalid login'], 401);
}
$user = Auth::user();
$token = $user->createToken('api-token')->plainTextToken;
return response()->json(['token' => $token]);
});
Step 7. Protect Routes
Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
return $request->user();
});
Conclusion: You have successfully implemented authentication in Laravel 12 using Breeze for frontend authentication and Sanctum for API security. This setup is widely used in real-world applications.
We always thanks to you for reading our blogs.
Dharmesh Chauhan
(Swapinfoway Founder)Hello Sir, We are brothers origin from Gujarat India, Fullstack developers working together since 2016. We have lots of skills in web development in different technologies here I mention PHP, Laravel, Javascript, Vuejs, Ajax, API, Payment Gateway Integration, Database, HTML5, CSS3, and Server Administration. So you need our service Please Contact Us
Haresh Chauhan
(Co-Founder)We Are Also Recommending You :
- Laravel Email Send
- Laravel Country State City Dropdown Using AJAX
- Laravel 10 Arr::pluck() Helper Function Use Example
- Join Query Same Table In Laravel
- Laravel Logs Viewer Integration
- Know All About Laravel Mixin Use In Vue Js With Example
- Laravel Custom Command Make Example
- Single Session User Login in Laravel
- Route Resource Controller Laravel
- Razorpay Payment Gateway Integration in Laravel 12 (2026) Step-by-Step Guide