Laravel 7/6 Email Verification Tutorial Example

In this tutorial you will learn about the Laravel 7/6 Email Verification Tutorial Example and its application with practical example.

In this Laravel 7/6 Email Verification Tutorial I will show you how to implement email verification for newly registered users in laravel. In this tutorial you will learn to enable email verification for account activation in laravel.

Laravel provides built-in email verification system for newly registered user. Using this, newly registered user will get an email with an account activation link. This activation link is used for account verification. When activation link is clicked, this will make user account verified and active for the application. Once user account is activated then it will be allowed to access protected routes; which can be accessible only by verified accounts.

Laravel 7/6 Email Verification Tutorial Example

In this step by step tutorial, we’ll show you how to setup email verification system for newly registered user in laravel.

  • Install Laravel Fresh Setup
  • Setup Database and SMTP Detail
  • Create Auth Scaffolding
  • Migrate Database
  • Add Route
  • Add Middleware In Controller
  • Run Development Server
  • Conclusion

1. Install Laravel Fresh Setup

First of all we need to create a fresh laravel project, download and install Laravel using the below command

2. Setup Database

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.

Now we will setup SMTP credential in .env to send emails. We are using mailtrap SMTP credential in this example.

3. Create Auth Scaffolding

Now we need to enable authentication scaffolding in laravel.

4. Migrate Database

Now, go to app/providers/AppServiceProvider.php and put the below code :

Now, in this step we will create model and migration file. Please run the following command:

After migrating the database tables we need to add the MustVerifyEmail Contracts in App/User.php. Open the App/User.php file add the constructor like

5. Add Route

After this, we need to define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.

routes/web.php

6. Add Middleware In Controller

We need to add Middleware in the controller constructor. Go to app/controllers/HomeController
and put this line $this->middleware([‘auth’, ‘verified’]); inside of constructor :

7. Run Development Server

Now we are ready to run our example so lets start the development server using following artisan command –

Now, open the following URL in browser to see the output –

In this tutorial we have learn about the Laravel 7/6 Email Verification Tutorial Example and its application with practical example. I hope you will like this tutorial.