laravel/breeze
Laravel Breeze is a minimal, simple authentication starter kit for Laravel 11.x and earlier. It provides login, registration, password reset, email verification, and basic scaffolding to kickstart new apps.
Installation:
composer require laravel/breeze --dev
php artisan breeze:install blade # or vue/react/livewire
npm install && npm run dev
php artisan migrate
blade, vue, react, or livewire) during installation.First Use Case:
/login to test authentication flow./register.AuthServiceProvider).Key Files to Explore:
app/Http/Controllers/Auth/ (Login, Registration, Password controllers).resources/views/auth/ (Blade templates) or resources/js/Pages/Auth/ (Inertia/Vue/React).routes/web.php (Authentication routes).app/Providers/AuthServiceProvider.php (Guard configuration).LoginController/RegisteredUserController as base classes.LoginRequest/RegisterRequest:
public function rules()
{
return [
'email' => ['required', 'string', 'email', 'max:255'],
'password' => ['required', 'string', 'min:8'],
// Custom rules
'terms' => ['accepted', 'required'],
];
}
ForgotPasswordController/NewPasswordController for custom logic (e.g., add CAPTCHA):
protected function validator(array $data)
{
return Validator::make($data, [
'email' => ['required', 'email'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
'captcha' => ['required', 'string', 'captcha'], // Custom rule
]);
}
AuthServiceProvider to add guards (e.g., API token auth):
protected function guard()
{
return auth()->guard($this->apiGuard) ?: parent::guard();
}
auth middleware in routes:
Route::middleware(['auth:sanctum'])->group(function () {
// API routes
});
app/views/layouts/app.blade.php for shared layouts.
Use @auth directive for conditional rendering:
@auth
<a href="{{ route('dashboard') }}">Dashboard</a>
@else
<a href="{{ route('login') }}">Log In</a>
@endauth
resources/js/Pages/Auth/.
Example: Override Login component props:
interface Props extends PageProps {
status: string;
canResetPassword: boolean;
customField?: string; // Add custom prop
}
AuthServiceProvider:
protected $policies = [
'App\Models\User' => [VerifiesEmails::class],
];
resources/views/emails/verification.blade.php.Route::middleware(['auth', 'password'])->group(function () {
// Routes requiring password confirmation
});
resources/views/auth/confirm-password.blade.php.Database:
users table by default. Extend with migrations:
php artisan make:migration add_custom_field_to_users_table --table=users
User model:
protected $fillable = ['name', 'email', 'password', 'custom_field'];
Testing:
actingAs() in tests:
$user = User::factory()->create();
$this->actingAs($user);
API Stack:
breeze:install api to skip frontend assets.Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
return $request->user();
});
Customization:
php artisan vendor:publish --tag=breeze-stubs
resources/css/app.css (Tailwind).Middleware Conflicts:
auth middleware is not duplicated in route groups.Route::middleware(['auth:sanctum', 'throttle:6,1']) instead of separate groups.CSRF Token Mismatch:
APP_URL is misconfigured.APP_URL in .env to match your dev/prod domain.Session Driver Issues:
SESSION_DRIVER=file or database in .env..env:
SESSION_DRIVER=file
SANCTUM_STATEFUL_DOMAINS=localhost:3000
TypeScript Errors (Inertia/Vue/React):
@types or incorrect tsconfig.json.npm install --save-dev @types/node and rebuild:
npm run dev
Email Verification Loop:
verified_at is not updated.VerifyEmails trait and User model observers.Tailwind Conflicts:
!important sparingly; extend Tailwind config in tailwind.config.js:
module.exports = {
important: true,
// ...
}
Authentication Logs:
APP_DEBUG=true
storage/logs/laravel.log for auth failures.Inertia/Vue/React Debugging:
Inertia.debug() in app/Http/Middleware/HandleInertiaRequests.php:
public function share(Request $request): array
{
return array_merge(parent::share($request), [
'appName' => config('app.name'),
'debug' => app()->environment('local'),
]);
}
Database Seeding:
users table is corrupted:
php artisan migrate:fresh --seed
Sanctum Token Issues:
php artisan sanctum:prune
SANCTUM_STATEFUL_DOMAINS includes all frontend domains.Custom Auth Logic:
php artisan breeze:auth
LoginController:
public function authenticated(Request $request, $user)
{
// Custom logic (e.g., log activity)
event(new Authenticated($request, $user));
}
Multi-Factor Authentication (MFA):
laravel-2fa:
composer require robinschmiedt/laravel-2fa
User model:
use RobinSchmiedt\TwoFactorAuth\Traits\TwoFactorAuthenticatable;
Socialite Providers:
composer require laravel/socialite
SocialAuthController:
public function redirectToGitHub()
{
return Socialite::driver('github')->redirect();
}
Custom User Model:
User model:
class User extends Authenticatable implements MustVerifyEmail
{
use HasApiTokens, HasFactory, Notifiable, TwoFactorAuthenticatable;
// Custom traits/methods
}
AuthServiceProvider:
protected $model = \App\Models\User::class
How can I help you explore Laravel packages today?