Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

laravel
communitycreator

What is basic authentication in Laravel 8 using Laravel Breeze?

Zubair Idris Aweda

Authentication is an important feature and basic requirement in web applications these days. Developers spend lots of time building authentication modules for every application they create.

However, this manual approach can get tiring and is a bit unproductive. Laravel, along with Laravel Breeze, let’s you focus about core application features while it takes care of authentication for you.

Prior knowledge of PHP is recommended for this shot.

What is Laravel Breeze?

Laravel Breeze is a minimal, simple implementation of all of Laravel’s authentication features, including login, registration, password reset, email verification, and password confirmation.

Laravel Breeze automatically scaffolds your application with the routes, controllers, and views you need to register and authenticate your application’s users.

In older versions of Laravel, there were other ways to generate the authentication scaffolds easily, too.

  • In Laravel 7, there was the Laravel/UI. Unlike Laravel Breeze, it used Bootstrap instead of Tailwind CSS.
  • In versions earlier than 6, you could generate the scaffolds using php artisan make:auth.

Laravel Breeze is the most recent development over previous versions.

Laravel Breeze saves you a lot of time, and makes your application less error-prone. This is because the scaffolds Laravel Breeze generates have been confirmed to be the best by Laravel professionals.

Before we get started, you should have composer and Laravel installed to continue. You can install composer here and Laravel here.

How to install Laravel Breeze

composer require laravel/breeze --dev

After the installation finishes, run the breeze:install command to publish the authentication views, routes, controllers, and other resources to your application.

Laravel Breeze gives you full control over your features and implementation by publishing its code to your application.

php artisan breeze:install

After running this command, you should see a few changes to your files. Here are some that you should take note of:

  • It has created auth controllers (quite a few of them) to handle registration, login (authentication) and logout, password confirmation, email verification, and password reset and update (it even sends an email).

  • It has also created views to match all controller actions using Tailwind CSS.

  • There’s a dashboard view where users get redirected to on successful authentication.

  • It has modified the landing page to include links to authentication pages.

  • It has created CSS and JavaScript files too, which need to be compiled later.

  • There are now authentication-related routes that are stored in the auth.php routes file.

  • Tests are also included in the tests directory.

How to compile static assets

We’ll want to minify the CSS and JavaScript files that were generated in the css and js folders in the resources folder, respectively.

This will give us faster load time and will also result in a reduced number of HTTP requests, since all JavaScript and CSS files have been compiled down to one file each.

Since Laravel gives you the freedom to use your own CSS pre-processor, you will want to compile your code down to what the browser can interpret.

Next, we compile our static assets to complete the installation. You can do so by running these commands:

npm install
npm run dev

This might take a while, depending on your internet speed.

Complete compilation
Complete compilation

Notice also that in your public folder, you now have css and js directories that hold compiled files that you can use in your code.

How to configure the database and migrate

As a final step, you need to configure your database and run migrations, since whatever data you’ve gotten from your users cannot currently be stored.

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=breeze
DB_USERNAME=root
DB_PASSWORD=
php artisan migrate

Now you’re all set, and you can run your application:

php artisan serve

Head on over to http://localhost:8000 to see your application running.

Updated landing page
Updated landing page

You can see all the various pages like the Login page, Forgot Password page, Register page, and Dashboard.

widget
widget
widget
widget

And there you have it. You’ve successfully installed and set up Laravel and Laravel Breeze.

RELATED TAGS

laravel
communitycreator
RELATED COURSES

View all Courses

Keep Exploring