Laravel 8 Tutorial - Authentication

In this tutorial, we are going to learn about authentication in Laravel 8. Authentication is the process of identifying user credentials.

In web applications, authentication is managed by sessions, which take input parameters such as email or username and password for user identification. If these parameters match, the user is said to be authenticated.

So, let's see how we can create authentication in Laravel 8. First, let's create a new Laravel 8 project.

To create a new project, go inside the htdocs directory and open the command prompt. Run the following command:


composer create-project --prefer-dist laravel/laravel laravel8auth.

All right, now the project has been created. Let's open this project inside Visual Studio Code.

Switch to Visual Studio Code and click on "Add Folder". Browse to the project directory and select "laravel8auth".

Now, let's create a new database. Switch to the browser and open localhost/phpmyadmin. Click on "Databases" and create a new database named "laravel8authdb".

Now, switch to the project and open the .env file. Add the database, username, and password:


DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel8authdb
DB_USERNAME=root
DB_PASSWORD=

Save the file. Now, let's install the Laravel Jetstream package.

Switch to the command prompt and go inside the project directory:


cd laravel8auth

Now, install the Laravel Jetstream package:


composer require laravel/Jetstream

Next, install Livewire:


php artisan jetstream:install livewire

All authentication scaffolding is now generated. Let's see the changes.

Switch to the project and go to the app directory. Then, go to the Actions directory. You can see that these files are generated for the authentication system:

This is for creating a new user. This is for updating a user's password. This is for forgetting a password.

Inside the views directory, you can see the auth directory. Inside this directory, these files are generated: Login, Register, Reset Password.

Now, let's migrate the migration. Switch to the command prompt and type:


php artisan migrate

Inside the database, you can see that these tables are created, which are used by the authentication system.

Now, build the asset by running the following command:


npm install && npm run dev

Now, let's run the application. Type:


php artisan serve

Switch to the browser, and you can see the login and register links. Click on the register link first and let's register a new user.

Enter your name, email, password, and confirm password. Click on register.

All right, the user is created. Now, let's login. Enter your email and password. Click on login.

You can see the user dashboard. This is the profile page. From here, you can upload your profile image. You can change your password from here. From here, you can logout. You can also reset your password.

Just click on the "Forgot your password" link. Enter your email, and it will send a password reset link to your email.

So, in this way, you can create an authentication system in Laravel 8.