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.
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}"
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',
];
}
app/routes/web.php
file and add: Auth::routes(['verify' => true]);
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:
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)
* Be the first to Make Comment