Authentication with Breeze Laravel

Authentication with Breeze Laravel

Authentication with Laravel Breeze

Laravel Breeze provides a simple and lightweight authentication system, including login, registration, password reset, and email verification. It is the perfect starting point for Laravel authentication, especially for small to medium-sized projects.

Step 1: Install Laravel Breeze

First, make sure you have a Laravel project set up. If you don’t have one, create a new Laravel project:

composer create-project laravel/laravel my-app cd my-app

Now, install Laravel Breeze via Composer:

composer require laravel/breeze --dev

Step 2: Install Breeze Authentication

Once Breeze is installed, you need to publish its authentication scaffolding:

php artisan breeze:install

You'll be prompted to choose between different stack options (Blade, Vue, React, etc.). The default option is Blade, but you can specify a frontend stack:

php artisan breeze:install blade

For other frontend stacks, use:

php artisan breeze:install vue php artisan breeze:install react

Step 3: Migrate the Database

Make sure if the .env file is correctly configured for the database, then run the migrations:

php artisan migrate

Step 4: Install NPM Dependencies (For Tailwind CSS & JS Frameworks)

If you chose a frontend stack like Vue or React, install and compile assets:

npm install && npm run dev

If you're using Blade, this step is still recommended to build the Tailwind CSS styles.

Step 5: Start Your Laravel Development Server

Now, run the application:

php artisan serve

Visit:
http://127.0.0.1:8000/register – Register page
http://127.0.0.1:8000/login – Login page

Step 6: Customize Authentication

Modify Authentication Views

Laravel Breeze stores authentication views in resources/views/auth/. You can edit these files to customize the UI.

  • login.blade.php – Login form
  • register.blade.php – Registration form
  • forgot-password.blade.php – Password reset

Modify Authentication Routes

Breeze registers authentication routes in routes/auth.php. You can modify them if needed.

Step 7: Protect Routes with Authentication Middleware

To secure certain routes, wrap them in the auth middleware inside routes/web.php:

Route::middleware(['auth'])->group(function () { Route::get('/dashboard', function () { return view('dashboard'); })->name('dashboard'); });

This ensures only logged-in users can access the dashboard.

Conclusion

Laravel Breeze is a quick and efficient way to set up authentication in your Laravel application. It provides a simple scaffold that you can customize as needed. šŸš€

Would you like to extend Breeze with roles/permissions or integrate it with an API? 😊

Souy Soeng

Souy Soeng

Our website teaches and reads PHP, Framework Laravel, and how to download Admin template sample source code free. Thank you for being so supportive!

Github

Post a Comment

CAN FEEDBACK
close