Laravel Breeze: Your Quick Start Guide to Authentication
Laravel Breeze is a minimalist, simple, and easily customizable authentication scaffolding for Laravel applications. It provides a quick way to set up all the necessary authentication features, including login, registration, password reset, email verification, and password confirmation, with a choice of frontend technologies.
Unlike its more feature-rich sibling, Laravel Jetstream, Breeze focuses on simplicity, offering just the essential authentication features. This makes it an excellent choice for developers who prefer to build their UI from scratch or integrate it with an existing frontend without the overhead of additional features like teams or API management.
Why Choose Laravel Breeze? #
- Simplicity: Offers a bare-bones authentication system that is easy to understand and modify.
- Flexibility: Provides options for different frontend stacks (Blade, Livewire, React, Vue), allowing you to choose what best fits your project.
- Customization: Since it's built on simple Blade templates (or component-based frameworks), customizing the UI and backend logic is straightforward.
- Quick Setup: Get a fully functional authentication system up and running in minutes.
Prerequisites #
Before we begin, ensure you have the following installed on your development machine:
- PHP: Version 8.1 or higher.
- Composer: For managing PHP dependencies.
- Node.js & npm (or Yarn): For managing JavaScript dependencies and compiling assets.
- A Laravel Project: We'll assume you have a new or existing Laravel project. If not, you can create one using Composer:
composer create-project laravel/laravel my-breeze-app cd my-breeze-app
Installation Guide #
Follow these steps to integrate Laravel Breeze into your Laravel application.
Step 1: Install Laravel Breeze Composer Package #
First, navigate to your project's root directory in your terminal and install the Laravel Breeze package using Composer:
composer require laravel/breeze --dev
The --dev flag indicates that this package is only needed for development and testing, not for production.
Step 2: Install Breeze Scaffolding #
After installing the Composer package, you need to run the breeze:install Artisan command. This command will publish the authentication views, routes, controllers, and other resources to your application.
Breeze offers several frontend stacks. Choose one that suits your project:
- Blade (with Tailwind CSS):
php artisan breeze:install blade - Livewire (with Alpine.js & Tailwind CSS):
php artisan breeze:install livewire - React (with Inertia.js & Tailwind CSS):
php artisan breeze:install react - Vue (with Inertia.js & Tailwind CSS):
php artisan breeze:install vue - API (with Laravel Sanctum for SPA/Mobile):
php artisan breeze:install api
For most web applications starting with Breeze, blade is a common and easy-to-understand choice. You can also add the --dark flag for dark mode support (e.g., php artisan breeze:install blade --dark).
Let's proceed with the blade stack for this tutorial:
php artisan breeze:install blade
This command will scaffold the necessary files and prompt you to run npm install and npm run dev.
Step 3: Install NPM Dependencies & Compile Assets #
Breeze, regardless of the chosen stack, relies on Node.js packages for styling (Tailwind CSS) and frontend logic (Alpine.js for Blade/Livewire, React/Vue for their respective stacks). Install these dependencies and compile your assets:
npm install
npm run dev
npm installdownloads all the JavaScript dependencies defined in yourpackage.jsonfile.npm run devcompiles your assets (CSS and JavaScript) using Vite (or Webpack in older Laravel versions).
If you want to keep watching for changes during development, you can use npm run watch.
Step 4: Run Database Migrations #
Breeze sets up an authentication system that requires a users table in your database. Ensure your database connection is configured in your .env file, then run the migrations:
php artisan migrate
This will create the users and password_resets tables (among others) required for authentication.
Step 5: Start the Development Server #
Finally, start the Laravel development server to see your application in action:
php artisan serve
Now, open your browser and navigate to http://127.0.0.1:8000. You should see a login and registration link in the top right corner.
Exploring Breeze Features #
After installation, Laravel Breeze provides a full suite of authentication features:
- Registration: Create new user accounts.
- Login & Logout: Secure user sessions.
- Password Reset: Users can request a password reset link via email.
- Email Verification: (Optional) Requires users to verify their email address after registration. To enable this, ensure your
App\Models\Usermodel implements theIlluminate\Contracts\Auth\MustVerifyEmailinterface and configure your mail driver. - Password Confirmation: A security feature that re-prompts users for their password before accessing sensitive parts of the application.
Key Files and Locations: #
- Routes: You'll find the authentication routes in
routes/auth.php. These are automatically loaded byRouteServiceProvider. - Controllers: Authentication logic resides in
app/Http/Controllers/Auth/. - Views (for Blade stack): All authentication views are located in
resources/views/auth/. The main layout is typically found inresources/views/layouts/guest.blade.php(for auth pages) andresources/views/layouts/app.blade.php(for authenticated user dashboards).
Customization #
One of Breeze's strengths is its ease of customization. Since it publishes all its resources, you have full control over the look and feel, as well as the underlying logic.
Customizing Views #
If you've installed the Blade stack, you can directly modify the Blade templates in resources/views/auth/ to match your application's design.
For example, to change the login page's appearance, simply edit resources/views/auth/login.blade.php.
Customizing Controllers and Logic #
The authentication controllers in app/Http/Controllers/Auth/ are regular Laravel controllers. You can modify their methods to change the behavior of registration, login, etc. For instance, you might want to add additional fields to the registration process, which would involve modifying the RegisteredUserController and the corresponding view and migration.
Customizing Routes #
The routes defined in routes/auth.php are standard Laravel routes. You can add, remove, or modify them as needed. For example, if you want to change the URL path for login from /login to /sign-in, you would adjust the route definition in this file.
Conclusion #
Laravel Breeze provides an excellent, lightweight starting point for adding authentication to your Laravel applications. Its simplicity and flexibility, coupled with the choice of popular frontend stacks, make it a versatile tool for developers. By following this guide, you should now have a fully functional authentication system and the knowledge to customize it to fit your specific project requirements. Happy coding!