Authentication is a way to verify the identity of a user or system who is going to access certain resources. While accessing any website, or system the most common thing is authentication. It will prevent the system from unauthorized access. You need to manage that kind of security system which is called authentication. You can set for auth scaffolding in Laravel 10. Authentication can be done in two ways. Either you can use any pre-build system or you can create a custom one.
The Auth scaffolding in Laravel is a set of pre-built codes that provides the basic functionality required for user authentication in a web application. Laravel’s authentication scaffolding includes a set of views, controllers, routes, and middleware that provide the necessary functionality to register, log in, and log out users. However, Laravel provides Auth scaffolding using multiple libraries like Bootstrap, Vue JS, and React.
In this post, we will implement Auth using Bootstrap in Laravel 10. So, let’s take a look at the demo example.
By clicking on the register page, you will have the register form. From here, you can register your account.
After successful registration, you will be redirected to the dashboard page. The system is logged in now.
Similarly, you will have the login page form there you can login into the system.
You can reset your password. Therefore, an option to reset the password link is there.
Now let’s come to the post for having a built-in authentication system in Laravel.
Laravel 10 Client Side Form Validation Using Parsley JS
Prerequisites
We will be implementing Auth Scaffolding in Laravel 10 using Bootstrap. Hence, you need a Laravel 10 project setup. However, for creating a Laravel 10 project, you will require the below tools.
- PHP >=8.1
- Composer
- Apache/Nginx Server
- VS Code Editor (Optional)
- MySQL (version > 5)
Create Project For Auth Scaffolding in Laravel 10
You can install Laravel 10 using the composer by hitting the below command.
composer create-project --prefer-dist laravel/laravel form-validation
After the project setup, you need to configure the database.
Configure Database For Laravel 10 Project
In order to configure the database, you need to create it first. After creating the database, navigate to the project folder and find the .env file.
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE={{ DB_NAME }}
DB_USERNAME={{ DB_USER }}
DB_PASSWORD={{ DB_PASSWORD }}
Once, you add the DB credentials as shown above, the project is configured with the database.
Next, you need to install one package for the Laravel authentication system.
How to Upload Multiple Files in Laravel 10 with Validation
Install Laravel UI Package For Authentication
The Laravel UI package is a set of front-end scaffolding tools for Laravel. It allows developers to quickly scaffold the authentication and basic UI for their Laravel applications.
So, navigate to the terminal and hit the below command.
composer require laravel/ui
This command will install the scaffolding in the project.
You have installed the Laravel UI package for auth management. However, this package requires front-end auth scaffolding. Hence, we will be installing Bootstrap Auth scaffolding.
How to Upload a File with Validation in Laravel 10
Install Laravel Bootstrap UI Auth
Laravel Bootstrap Auth provides a convenient way to quickly add authentication functionality to your Laravel application without having to write code from scratch. This saves time and effort and allows developers to focus on building the core features of their applications.
Hence, you need to install the Bootstrap auth using the below command.
php artisan ui bootstrap --auth
The command will generate the authentication scaffolding as shown below.
However, you need to install npm for managing front-end authentication.
npm install && npm run dev
After hitting the above command, you can see the result. The npm added front-end dependencies for the authentication.
Now, you can run the application to see the result.
php artisan serve
Final words
We have implemented Laravel Auth scaffolding using the Laravel UI package. But, in order to manage the authentication, Laravel UI requires front-end dependencies for auth scaffolding. Hence, we generated using Bootstrap.
Leave a Reply