Simple Authentication in Laravel 8.9.0 step-by-step with images
Tags: laravel, php
Published: 2020-10-07 19:42:26

There are 8 simple steps for laravel 8 authentication:
1- Create a laravel 8 project
2- "Laravel UI" package installation
3- "Auth scaffolding" Generation
4- "NPM" dependencies installation
5- Setup the database
6- Changings in a file
7- Migration
8- Test the project

1- Create a laravel 8 project
First, we have to create a laravel project. To create a new project open the 'git bash' in the 'htdocs ' folder, make sure the folder path 'C:\xampp\htdocs' in git bash. Now type the following command in git bash to create a new project:

composer create-project laravel/laravel=8.0 auth

If you do not want to mention the laravel version then simply remove the "=8.0", in this case, the composer will automatically install the latest version of laravel. 'auth' is the project name.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/xnz3jj91zgmzla2jxo14.PNG)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/s4ndf7nhda3jxdkmnfpi.PNG)

2- "Laravel UI" package installation
Once the project is created, Now change the folder address by typing:

cd auth

or open the git bash by right-clicking inside the folder 'auth' and then execute the following command to install the laravel UI package:

composer require laravel/ui

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/0t0nekbu8gqbynzfrge4.PNG)

3- "Auth scaffolding" Generation
After successfully installation of laravel UI package now execute the following command to scaffold the auth with vue, bootstrap or react, etc.

php artisan ui vue --auth

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/clg6jmwj723e6nxty51h.PNG)

4- "NPM" dependencies installation
In the final step, execute the following command to make frontend more attractive and beautiful:

npm install && npm run dev

If you found the error 'bash: npm: command not found'

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/e76gjlvz1mj29d2b3ceq.PNG)

Then download and install the node.js pre-build install: https://nodejs.org/en/download/
and again execute this command.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/v6hvpzukbr0si2uzbcih.PNG)

5- Setup the database
Run the localhost and open the phpmyadmin and create a new database

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/3evzklt3oqwno29akd79.PNG)

Now open the project folder in an editor and open the .env file and change the 'DB_DATABASE' name to your database name:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/hcjsv000nvmxoieltirg.PNG)

6- Only 1 line change in 'AppServiceProvider.php' file
Open the AppServiceProvider.php file in 'app/providers/AppServiceProvider.php':

Add 'use Illuminate\Support\Facades\Schema;' outside of the class and type 'Schema::defaultStringLength(191);' in the boot function.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/hslksfsnx10fg9u12h33.PNG)

7- Migration
Now save all the files and type the following command in the git bash and press enter:

php artisan migrate

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/mhxe67durj1olneh2st3.PNG)

8- Test the project
Laravel authentication is successfully created. Now run the project on a localhost server 'http://localhost/auth/public/':

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/3ob2gcug1p3f92pyt9ef.PNG)

Click on the 'Register' button for registration and add you details and click register:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/cg3qca7n7as18ubavg94.PNG)

And you are logged in:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/vzxg36en87acw5wxqio2.PNG)

You can also see, edit, or delete the registered users in phpmyadmin:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ghosb4507fvih0axxf7c.PNG)

--I hope it helps!