Skip to main content

Login/Register with Laravel Breeze

Lesson 09/15 4 min read
Autoplay

Lesson Overview

- Understanding starter kits for authentication
- Installing and configuring Laravel Breeze
- Managing authentication routes
- Setting up user dashboard

IMPORTANT: this course is for older Laravel 11, released in 2024. We have a new VIDEO course for the LATEST version: Laravel 12 for Beginners: Your First Project.


Until now, we have been working with existing data and only showing it, not entering it. Now, let's look at how we can manage the data.

We will create a simple admin panel to manage categories and posts. For that, we will create a separate Laravel project based on the same Models and database structure. Why do we need a separate project? Two reasons:

  1. Starter Kits. Laravel has starter kits to help with authentication and authorization. Features like login, logout, and register come out of the box with Laravel ecosystem packages. This course will use Laravel Breeze because it is simpler. Starter kits must be installed on a fresh Laravel project because they overwrite some files. That's why we can't use our existing project.
  2. Visual Design. We have used a simple Bootstrap template for the front page. Starter kits use Tailwind, which would also conflict with our current project code.

Notice: Tailwind is not a requirement to use Laravel. If you still prefer Bootstrap, there's a separate older laravel/ui starter kit for that.


So, when you create a new project using Laravel Installer, you may choose to install a starter kit. We will select Laravel Breeze with the stack Blade with Alpine. The testing framework doesn't matter, as we won't write tests in this course.

If you have created a new Laravel project without choosing a starter kit, you can install Laravel Breeze as any other package using Composer.

composer require laravel/breeze

Next, let's re-create the same Models with Migrations as in previous lessons.

php artisan make:model Category -m
php artisan make:model Post -m
public function up(): void
{
Schema::create('categories', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
});
}

database/migrations/xxx_create_posts_table.php:

public function up(): void
{
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->text('text');
$table->foreignId('category_id')->constrained();
$table->timestamps();
});
}

Migrate the database.

php artisan migrate

The home page looks the same as a default Welcome page but has two new links to the Login and Register pages at the top right.

The Breeze register page looks as in the image below.

After registering, we see the Breeze dashboard.

This way, using Laravel Breeze, we have a simple design for logging in, registering, and updating profile pages.


Breeze New Routes

Laravel Breeze automatically adds a few routes below the default Welcome page.

routes/web.php:

use App\Http\Controllers\ProfileController;
 
Route::get('/', function () {
return view('welcome');
});
 
Route::get('/dashboard', function () {
return view('dashboard');
})->middleware(['auth', 'verified'])->name('dashboard');
 
Route::middleware('auth')->group(function () {
Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
});
 
require __DIR__.'/auth.php';

The first route is for the /dashboard URL. It has an additional method, middleware, with auth as a parameter. It means that only authenticated logged-in users can access that page.

The second is a group of routes for the user profile. This group also has an auth Middleware. We will talk more about Middleware and Route groups in later lessons.

And on the last line, Breeze adds a link to a separate Auth routes file. In that file, we can see all the Routes required for the authentication: login, registration, logout, forgot password, etc.

routes/web.php:

use App\Http\Controllers\ProfileController;
 
Route::get('/', function () {
return view('welcome');
});
 
Route::get('/dashboard', function () {
return view('dashboard');
})->middleware(['auth', 'verified'])->name('dashboard');
 
Route::middleware('auth')->group(function () {
Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
});
 
require __DIR__.'/auth.php';

If you open the routes/auth.php file, there are two groups of Routes with different Middlewares: guest and auth. The guest Middleware is used when Routes should be accessed only for unauthenticated users, like login or register pages.

routes/auth.php:

Route::middleware('guest')->group(function () {
// ...
});
 
Route::middleware('auth')->group(function () {
// ...
});

So yeah, now we have all the login/register functionality. Wasn't it a breeze? :)

In the following lessons, we will manage the categories and posts as administrators.

Syed Muhammad Daniyal Murtaza Zaidi avatar
Syed Muhammad Daniyal Murtaza Zaidi

while installing breeze manually:

after running:

composer require laravel/breeze

then another (given below command) should be run:

php artisan breeze:install

otherwise the login and register option will remain invisible.

👍 5
Nerijus avatar

Or install with a new laravel project

The Alien avatar

Thanks for the wonderful tutorials ! After installing the breeze getting the followin error message : -

Illuminate\Foundation\ViteManifestNotFoundException

Vite manifest not found at: C:______ public\build/manifest.json

Please help so i could continue learing

Thanks

Syed Muhammad Daniyal Murtaza Zaidi avatar
Syed Muhammad Daniyal Murtaza Zaidi

Try running: sudo npm run dev in a separate terminal, and: php artisan serve at another, simultaneously.

Nerijus avatar

Sudo isnt needed. artisan server should also be

The Alien avatar

I am on windows .. . not on ubuntu , do i need to isntall node.js first and

Nerijus can you give me more details about it.. . "Sudo isnt needed. artisan server should also be"

Nerijus avatar

Yes you must install node. It's a dev environment, how you set up it's up to

Windev avatar

Besides using breeze to log in and register, is there any other way?

Nerijus avatar

Jetstream, fortify, your own logic

dimis lakis avatar

Ok I set up breeze, but we have to look at the database of the other project. How to do it?

Nerijus avatar

What do you mean "database of the other project"?

dimis lakis avatar

We created a new project with breeze, we have already another "project" with the other sqlite db with categories and post, how to set up the same db? Thank you for the answer.

dimis lakis avatar

I set at the "Breeze" project the partial path of the other db

Nerijus avatar

One project should use one db. Especially locally there's nothing wrong to have sqlite for every project. Which you should do.

dimis lakis avatar

Ok I had the problem that I created seperate dbs and now I set up the same, online I should use maybe mysql.Thank you for the tutorial, I learn a lot.

Nerijus avatar

Locally you should use the same db as in prod

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.