Consent

This site uses third party services that need your consent.

Skip to content
Steven Roland

Understanding Laravel Breeze

Laravel Breeze is a lightweight and minimalistic authentication package for Laravel applications. It provides a simple way to implement essential authentication features such as login, registration, password reset, email verification, and profile management. Breeze is designed to be easy to use and customize, making it a great starting point for new Laravel projects or for quickly adding authentication to existing projects.

Key Features

  • Authentication Functionalities: Breeze includes pre-built components for login, registration, password reset, email verification, and profile management, saving developers significant time and effort.

  • Blade Templates with Tailwind CSS: The default view layer in Breeze utilizes Blade templates styled with Tailwind CSS, allowing for easy customization of the authentication UI.

  • Frontend Flexibility: Breeze supports additional scaffolding options with Livewire or Inertia, allowing integration with popular JavaScript frameworks like Vue.js and React.js.

  • Profile Management: Users can edit their profile information directly within the application.

Installing Laravel Breeze

To get started with Laravel Breeze, you need to have a Laravel application set up. Here’s how you can install and configure Breeze:

  1. Create a New Laravel Project: If you haven't already, create a new Laravel project.

    composer create-project laravel/laravel my-project
    cd my-project
  2. Install Laravel Breeze: Use Composer to require the Breeze package.

    composer require laravel/breeze --dev
  3. Run the Breeze Installer: This command publishes the necessary authentication views, routes, and controllers.

    php artisan breeze:install
  4. Compile Frontend Assets: Install Node dependencies and compile the assets.

    npm install
    npm run dev
  5. Run Migrations: Set up the database tables required for authentication.

    php artisan migrate

After completing these steps, you can navigate to your application's /login or /register URLs to see Breeze in action.

Example Code and Usage

Here’s a basic example of how you might customize the registration form in a Laravel Breeze application:

  1. Customize the Registration Form: Open resources/views/auth/register.blade.php and add a new field, such as a phone number field.

    <div class="mt-4">
        <x-input-label for="phone" :value="__('Phone')" />
        <x-text-input id="phone" class="block mt-1 w-full" type="text" name="phone" :value="old('phone')" required autocomplete="phone" />
        <x-input-error :messages="$errors->get('phone')" class="mt-2" />
    </div>
  2. Modify the Controller: Update the RegisteredUserController to handle the new field.

    protected function create(array $data)
    {
        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'phone' => $data['phone'], // Add this line
            'password' => Hash::make($data['password']),
       ]);
    }
  3. Update the Migration: Ensure your users table migration includes the new field.

    $table->string('phone')->nullable();

Frontend Options in Laravel Breeze

Laravel Breeze offers a variety of options for frontend scaffolding, allowing developers to choose the stack that best fits their needs. Here's a detailed look at the available options:

1. Blade with Alpine.js

  • Blade Templates: Breeze's default setup uses Blade templates, which are simple and easy to use for rendering views in Laravel. This is ideal for developers who prefer a straightforward PHP-based templating approach.

  • Alpine.js: This lightweight JavaScript framework is often used in conjunction with Blade to add interactivity to web pages. Alpine.js is similar to Vue.js in syntax but is much simpler and more lightweight, making it suitable for adding small amounts of JavaScript behavior directly into HTML.

2. Livewire

  • Livewire: This is a powerful framework for building dynamic, reactive front-end interfaces using PHP. Livewire allows developers to create components that can handle frontend interactions without writing JavaScript. It's a great choice for those who prefer to stay within the Laravel ecosystem and want to avoid the complexity of JavaScript frameworks.

  • Volt API: A recent addition to Livewire is the Volt API, which provides a functional approach to building Livewire components. This can be particularly appealing to developers familiar with functional programming paradigms.

3. Inertia.js

  • Inertia Vue/React: Inertia allows you to build modern single-page applications (SPAs) using Vue.js or React.js while keeping the routing and data fetching logic in Laravel. This approach provides a seamless integration between the Laravel backend and a JavaScript frontend, allowing developers to leverage the full power of Vue or React.

  • Vue.js and React.js: These popular JavaScript frameworks are supported by Inertia, enabling developers to build complex, interactive user interfaces. This is ideal for projects that require rich client-side interactions and a modern JavaScript ecosystem.

4. API-Only

  • API-Only: For applications that require a decoupled frontend, Laravel Breeze can be set up with an API-only stack. This is useful for developers who want to build a separate frontend application using a framework like Next.js or Nuxt.js, while Laravel handles the backend API.

Example Installation Commands

To install Laravel Breeze with a specific frontend stack, you can use the following commands:

  • Blade with Alpine.js:

    php artisan breeze:install blade
  • Livewire:

    php artisan breeze:install livewire
  • Inertia with Vue:

    php artisan breeze:install vue
  • Inertia with React:

    php artisan breeze:install react
  • API-Only:

    php artisan breeze:install api

Comparison: Laravel Breeze vs. Laravel Jetstream

Laravel Breeze and Laravel Jetstream are both starter kits for Laravel, but they cater to different needs and use cases. Here's a quick comparison:

Feature Laravel Breeze Laravel Jetstream
Complexity Simple and minimalistic More advanced with additional features
Features Basic authentication (login, registration, etc.) Includes two-factor authentication, session management, team management, etc.
Frontend Options Blade with Alpine.js, Livewire, Inertia (Vue/React) Livewire or Inertia (Vue/React)
Use Case Quick setup for simple applications Comprehensive setup for applications needing advanced features
Customization Full control over published code Uses Laravel Fortify for authentication backend

When to Use Each

  • Laravel Breeze is ideal for developers who want a straightforward authentication system with minimal setup. It is perfect for applications that primarily use Blade templates or for those who need to quickly implement authentication without the complexity of additional features like team management or two-factor authentication.

  • Laravel Jetstream is suitable for developers who need a more robust and feature-rich starting point. It includes advanced features such as team management and two-factor authentication, making it ideal for applications that require these functionalities.

Both Breeze and Jetstream offer excellent features for building authentication systems, and the choice between them depends on the specific needs and complexity of your project.

More posts

Creating a Sleek Modal Component with Alpine.js

Learn to build an interactive modal component using Alpine.js. This tutorial covers basic implementation, styling enhancements, accessibility features, and Alpine.js directives. Create a sleek, functional modal that improves user experience with minimal JavaScript.

Building a Dynamic Dropdown Menu with Alpine.js

Learn how to create a dynamic dropdown menu using Alpine.js. This tutorial covers basic implementation, enhancing with styling and accessibility, and leveraging Alpine.js features like x-data, x-show, and transition effects for a sleek user interface.