DEV Community

Cover image for Creating Email Verification in Laravel
Hilmi Hidayat
Hilmi Hidayat

Posted on • Updated on

Creating Email Verification in Laravel

Laravel Email Verification - In this article I will explain how to make email verification in Laravel using the mailtrap service. To make email verification with mailtrap is quite easy. And here are the steps to make email verification with mailtrap in laravel:

Don't forget to install the laravel project and install laravel ui for the authentication feature. And also don't forget to create a new database, adjust DB_DATABASE in .env and run php artisan migrate.

  1. The first step, we we must first register in mailtrap. If you have registered, we will get a mailtrap username and password as shown below. Laravel Email Verification

Next we can copy the script marked above, then paste it in the .env file so that the .env file will look like below
Setup Laravel Email Verification

  1. Next, open the User model and add implements MustVerifyEmail as shown below. add implements MustVerifyEmail
  2. In Step three, add route Auth::routes(['verify' => true]); in routes/web.php. So that the display in the web.php file will be like below add route Auth::routes(['verify' => true]);
  3. And the last step is adding 'verify' middleware in HomeController. So the display in the HomeController will be like the image below. adding 'verify' middleware in HomeController By adding the verify middleware, it means that the controller or home page that is called on this controller can only be accessed by users whose emails have been verified.

OK, now we try to verify the email by registering first. run php artisan serve, then open our project in the browser. Go to the register menu and enter your name, email, password and confirm password as in the example below.
try to verify the email by registering first
When you click register, you will be directed to the email/verify page as shown below.
directed to the email/verify page
And if we check again on the mailtrap, there will be a new email that comes in as below.
check on the mailtrap
If we click Verify Email Address, then we will be directed to the homepage or our project home page.

Thank's for your attention and don't forget to visit Codelapan.com, to get articles about web programming, web design, and others.

Top comments (0)