Laravel 10 Authentication with Breeze TutorialSunday April 09, 2023
Laravel provides a built-in authentication service that handles authorization in the application. It has several authentication methods which include email and password authentication, social media authentication, and token-base authentication for RESTful APIs. For the web interface, Laravel’s authentication contains login, registration, email verification, and password reset feature.
Breeze is a package that implements authentication features quickly and easily. It scaffolds authentication in your Laravel application with Blade, React, and Vue.
In this article, we will learn about implementing authentication through the Breeze package, for that first you need to install Laravel fresh application.
1. Install Laravel Fresh Application
So let’s begin with installing the Laravel application. Go to your web server and run the following command,
composer create-project laravel/laravel your-laravel-project-name
You can replace your-laravel-project-name with a desired name or project name.
The command is a bit longer, right? If you want to make it shorter for your future project then run the below command that will install the Laravel installer globally.
composer global require laravel/installer
Once the installer is installed through composer then you can use the below command which is simple and shorter.
laravel new your-project-name
After running the above command composer will take some time to install the fresh Laravel application. Usually, it takes a few seconds only.
Next, you need to create a database in your web server and add the connection details to the environment file (.env) which is located in the root directory.
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=auth_app_db DB_USERNAME=root DB_PASSWORD=
If your web server has a password then don’t forget to add it, I didn’t set any password that’s why I am leaving it blank.
2. Install Laravel Breeze Package
After installing the Laravel application, we can install the Laravel Breeze package. Before installing you need to make sure that you have entered the project directory. You can enter your project directory through the below command,
Next, run the below command to install the Breeze package.
composer require laravel/breeze --dev
Once the composer installed the Breeze package then you need to run the below artisan command.
php artisan breeze:install
The breeze:install artisan command publishes all the resources into your Laravel application. After running the above command, it will ask you a few questions.
Look at below my answer to the question that Breeze asked me during the installation,
1. Which stack would you like to install?
2. Would you like to install dark mode support?
3. Would you prefer Pest tests instead of PHPUnit?
Once the Breeze is installed then you need to create tables in your database through the artisan command. Run the below command,
php artisan migrate
The php artisan migrate command runs all the migrations from your Laravel application and creates the tables in the database.
Once the table is created through migration, that means all steps are completed and the Laravel Breeze Package is installed and ready for the test. So go to the terminal again and run the php artisan serve command that runs the Laravel application on the development server
php artisan serve
Then run the below URL in your browser,
Now you can use Laravel authentication, I registered a user through the registration form for testing purposes which works properly.