Laravel 5.7 Email Verification Tutorial With Example

Read about Laravel 5.7 Email Verification Tutorial With Example.

In this tutorial, you will learn to create registration process with email verification feature in laravel 5.7.

Laravel 5.7 comes with rich built-in authentication feature which requires very few tasks from developer to create high security level authentication for any laravel web application.

We will use mail trap to manage verification emails.

If you need an authentication system without email verification feature, read Laravel Registration and Login Example.

First of all, see the below video which contains the output of this laravel 5.7 email verification example

Now follow all the below steps.

Move 1. New Project

Create a new project with the below command

Move 2. Enable Authentication

In the terminal trigger the following command

Above command will generate the authentication scaffolding means that it will generate necessary files to enable authentication (registration, login, logout etc) in our laravel app.

  • Navigate to Http->Controller->Auth directory.
  • You will find some php files like RegisterController.php, LoginController.php, ForgotPasswordController.php etc. inside Auth folder.
  • These are programming logic related files.
  • To see view blade files navigate to resources->views->auth directory.
  •  Inside auth folder, you will find some blade files like login.blade.php, register.blade.php etc.

Move 3. Making a Database

Second task is to create a database for our project.

  • I am using sequel pro for database management. If you are using phpMyAdmin or other one than don’t worry, process will be the same.
  • Make a new database and give it a name like “laraMailVeri” in sequel pro or phpMyAdmin or any other tool.
  • Now we need to connect this newly created database with our laravel project.

So in your project, open the .env file. In this file, update the below code lines as per your configuration.

I have not set any password so I have set it as empty. Similarly, edit other fields as per your machine.

Now run the below command in terminal.

Above command will create necessary tables in our database.

So you just need to create database manually, tables and their fields will be created automatically.

Move 4. Changing User.php file

  • Open the app->User.php file.
  • By default this file do not implements MustVerifyEmail class. We need to do it manually.
  • So just add “implements MustVerifyEmail” at the first line of class definition.

Final source code for User.php file is as the below

Move 5. Adding Routes

Time to add some routes in the web.php file.

  • Open the routes->web.php file. Here, you may find something like ” Auth::routes(); “
  • Replace it with the below line

  • Now there is also another line like ” Route::get(‘/home’, ‘[email protected]’)->name(‘home’) ” 
  • Replace this line with the following

So the final source snippet for web.php file is like the below

Move 6. Mail Demo

Finally, let us send the verification e-mail. I am using mailtrap to manage verification mails.

  • Sign in to mail trap with this link https://mailtrap.io
  • After signing in to mail trap, we need to connect it with our laravel app. You can find information like username, password, port etc. on the mail trap dashboard.
  • We need to put this information in .env file.

Open your .env file and find the below lines

  • Here, in the above snippet, update information as per your mail trap dashboard.
  • After this muck of work, run your application using “php artisan serve” command.

Now you should be able to run your authentication with email verification feature.

Download Source Code for Laravel 5.7 Email Verification

Visit me to download Full Source Code

Hardik Parsania

I am mobile app developer. I am always passionate about solving complex and real world problems.I have developed many apps with great interest and superior logical skills.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *