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.
- 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.
- Next, open the User model and add implements MustVerifyEmail as shown below.
- 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
- And the last step is adding 'verify' middleware in HomeController. So the display in the HomeController will be like the image below. 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.
When you click register, you will be directed to the email/verify page as shown below.
And if we check again on the mailtrap, there will be a new email that comes in as below.
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.