Laravel 5.8 Email Verification Tutorial Example Step By Step

Laravel 5.8 Email Verification Tutorial With Example Step By Step.

Email verification is useful feature for providing more security to new users of your web site.

This feature ensures us that the user has given us the correct email address and he is the owner of the email id.

Laravel gives rich environment to implement email verification with laravel 5.8 version.

It provides some easy to go techniques which simplifies the authentication process for email verification.

Checkout the below youtube video to show the final outcome.

Move 1. Create a new project

First of all, fire the below command in your terminal.

  • Above command will make a new project with laravel 5.8 version. Name of the project will be “lara5.8mailveri
  • If you have already installed 5.8 version of laravel than you can use a small command “laravel new lara5.8mailveri” also.

Move 2. Start Authentication

Use the following command in terminal.

  • This command will enable the authentication scaffolding in our app.
  • After the execution of this command, you will be able to use simple register and login in your web site. (However, we still need to connect our project with database, we will do it in next step.)

System generates some necessary files for authentication using this command. Let us see these files.

  • Navigate to Http->Controller->Auth directory.
  • RegisterController.php, LoginController.php, ForgotPasswordController.php etc. files are there 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.

You can change the look and feel of registration as well login page using these blade files.

Move 3. Database Task

Now let us connect our laravel app with MySQL database.

  • I am using sequel pro as an administration tool for MySQL database. If you are using other tool like phpMyAdmin or any other  than don’t worry, the trick is the same for all of them.
  • Just create a new database in your tool and give it a name like “lara5.8MailVeri
  • Now come to your project and open .env file.

You need to edit below lines in this .env file.

  • My username is root and password is nothing so I have leave it as an empty.
  • Configure above lines as per your machine requirements.
  • After this, your laravel 5.8 project has connected with MySQL database.

Now, trigger the following command in terminal.

Above command will create some tables in our MySQL database.

Move 4. Updating user.php

  • Navigate to app->User.php file.
  • In this file, a class named “User” is there. By default, this class do not implements anything.
  • We need to implement MustVerifyEmail to this class manually.

After this, source code for User.php looks like the below

We just need to add implementation of MustVerifyEmail , no need to change other things.

Move 5. Writing Some Routes

Now let us add some routes in web.php file.

Navigate to 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 last source lines for web.php file looks like the below

Move 6. Final Demo Task

Now we need to have some email address tool which allows us to send verification mail.

  • I am using mailtrap for this.
  • So first of all, sign in to your mail trap account :
  • On the dashboard, you will see some configuration details like username, password, port etc.

We need to connect our project using these details. For this, open your .env file and see the below lines.

  • You just need to change above details as per your dashboard of mail trap.

Now all the tasks are done. Just run “php artisan serve” command from terminal and see that your laravel 5.8 project is doing really well with verification mail.

Download Source for laravel 5.8 email verification

 Link 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 *