Create a User Registration System with Email Verification in Laravel

In this tutorial I’m going to learn how to get email verification when someone register in laravel. Please follow some easy steps mentioned below. and will set up Mailtrap. We will use this service to test and send emails. Mailtrap simulates the actual SMTP server and delivers your emails to a test recipient.

First let’s go to install laravel project

composer create-project laravel/laravel mail-verification "5.8.*"

? Step 2 — Database Configuration

Setup database with your installed laravel 8 project . lets go to .env folder and put database name and connect to database.

DB_CONNECTION=mysqlDB_HOST=127.0.0.1DB_PORT=3306DB_DATABASE=laravel-mailDB_USERNAME=rootDB_PASSWORD=

Next click on create

Next set up to mail trap for getting mail

Go to this URL — MailTrapio

Go to .env and put your mailtrap credentials

MAIL_MAILER=smtpMAIL_HOST=smtp.mailtrap.ioMAIL_PORT=2525MAIL_USERNAME=puthere-----MAIL_PASSWORD=puthere-----MAIL_ENCRYPTION=nullMAIL_FROM_ADDRESS=nullMAIL_FROM_NAME="${APP_NAME}"

Now migrate the table

php artisan migrate

Now Create Auth

php artisan make:auth

Step 5: Email Verification Setup

Go to App/user.php file and paste below code

<?phpnamespace 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;    /**     * The attributes that are mass assignable.     *     * @var array     */    protected $fillable = [        'name', 'email', 'password',    ];    /**     * The attributes that should be hidden for arrays.     *     * @var array     */    protected $hidden = [        'password', 'remember_token',    ];    /**     * The attributes that should be cast to native types.     *     * @var array     */    protected $casts = [        'email_verified_at' => 'datetime',    ];}

Next go to Set-up Routes

Routes/web.php

Replace Auth:Routes to below code

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

Next go to HomeController.php file and paste below function code

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

Now set-up is completed run below code

php artisan serve

Now page is look like this

Now you got successfully got verification email

Now also you’ll get email when register

Login successfully when you verify email

Thanks i hope its helpful 

Related Posts

Blade in Laravel

Blade is the simple,yet powerful templating engine that is included with laravel. Blade does not restrict you from using plain php code in your templates. Blade templates…

Read More

CRUD USING QUIRY BUILDER IN LARAVEL.

We are performing crud opertion using quiry builder in laravel STEP : 1 Create Laravel project by running this command in terminal CMND :– Laravel new project_name…

Read More

Controller In Laravel

Controllers can group related request handling logic into a single class, Instead of defining all of your request handling logic as closure in route files ,you may…

Read More

LARAVEL ROUTING

All Laravel routes are define in route files , which are located in the route directory ,These file are automatically loaded by the framework. The most basic…

Read More

MVC (MODEL VIEW CONTROLLER)

MVC stands for Model–view–controller. The MVC is an architectural pattern model that seprates an applications into three logical components.(Model , View, Controller) MVC was first introduce in…

Read More

ReflectionException : Class BlogsTableSeeder does not exist

When i type php artisan db:seed command. It’s showing this type of errors. [ReflectionException]Class UserTableSeeder does not exist Here is my BlogsTableSeeder <?phpuse Illuminate\Database\Seeder;class BlogsTableSeeder extends Seeder{…

Read More
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x