alexa
Facebook
Twitter
LinkedIn
Instagram
Whatsapp
Call Now
Quick Inquiry

Laravel 7 Email Verification Tutorial with Example

Laravel 7 Email Verification Tutorial with Example

How to Implement Email Verification in Laravel 7?

Today's post is on the email verification system in laravel 7.


In today's time, the number of spamming people is very much, due to this, all the big websites you will see, when a new user registers in it, an email confirmation link is sent to the mail id given by him and when he clicks on that link. Then the registration process is complete and if he does not verify his email then he is not able to login either.

I assume that you have kept the basic file set up for Laravel 7/6.
So now we are showing you in Laravel 7 how to verify any registered user.

Step1: Open your .env file and Configuring the SMTP Server

 MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=youremail@domain.com //Write here your gmail id (like info@gmail.com)
MAIL_PASSWORD=*****************     //Type the actual password of above gmail (12345678)
MAIL_ENCRYPTION=tls
MAIL_FROM_NAME="${APP_NAME}"

Step2: Open User.php file (which are available in Root Directory App\User.php) replace your code with this code or

just add implements MustVerifyEmail

 <?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable implements MustVerifyEmail
{
    use Notifiable;
    protected $fillable = [
        'name', 'email', 'password',
    ];

    protected $hidden = [
        'password', 'remember_token',
    ];


    protected $casts = [
        'email_verified_at' => 'datetime',
    ];
}

Step 3: open the app/routes/web.php file and add:

 Auth::routes(['verify' => true]);

Step 4: open the app/Http/Controllers/HomeController.php file and add the verified middleware as follows:

  public function __construct()
    {
        $this->middleware(['auth', 'verified']);
    }

 

Now its to update your gmail Account setting:

Step 1 Login to gmail account and click on  Manage your Google Account

Step 2 Then Click on Security which available in right side menu tabs you will these option Off 

Less secure app access

To protect your account, apps and devices that use less secure sign-in

technology are blocked. To keep your account secure,

Google will automatically turn this setting OFF if it’s not being used. Learn more

Off

Turn on access (not recommended)

Step 3 Next Turn on for less secure app access

 


2184 0
7

Write a Comments


* Be the first to Make Comment

GoodFirms Badge
GoodFirms Badge

Fix Your Meeting With Our SEO Consultants in India To Grow Your Business Online