Laravel 5.8 Email Verification Example

Laravel 5.8 Email Verification Example

In this post we will give you information about Laravel 5.8 Email Verification Example. Hear we will give you detail about Laravel 5.8 Email Verification ExampleAnd how to use it also give you demo for it if it is necessary.

In this tutorial, i will share with you how to setup register user email verification in laravel 5.8. new user must be verify email address before logic in laravel 5.8. we will send activation code on register email address to verify email in laravel 5.8 app.

In laravel old version we are doing email verification process manually, but in laravel 5.8 they provide in build email verification setup for new registered users to must have to verify his email before proceed. You just need to make some basic setup with need to use middleware, routes and mail configuration.

Just follow this tutorial from scratch and you will set up for email verification in laravel 5.8 project.

Step 1: Install Laravel 5.8

First of all, we need to get fresh Laravel 5.8 version application using bellow command because we are going from scratch, So open your terminal OR command prompt and run bellow command:

composer create-project --prefer-dist laravel/laravel blog

Step 2: Database Configuration

In this step, we need to add database configuration details on .env file. So let’s create username, password etc. So let’s add.

.env

DB_CONNECTION=mysql

DB_HOST=127.0.0.1

DB_PORT=3306

DB_DATABASE=laravel572

DB_USERNAME=root

DB_PASSWORD=root

After added database configuration, you need to run default migration of laravel by following command:

php artisan migrate

Also see:Laravel 5.8 CRUD (Create Read Update Delete) Tutorial For Beginners

Step 3: Email Configuration

Here, we need to add email configuration in .env file. We are sending email after user registration so we need to add email smtp details for send email.

.env

MAIL_DRIVER=smtp

MAIL_HOST=smtp.gmail.com

MAIL_PORT=587

MAIL_USERNAME=youremail@gmail.com

MAIL_PASSWORD=yourpass

MAIL_ENCRYPTION=tls

Step 4: Create Auth

Laravel provide very quick way to create registration, login and forgot password with routes by auth command, So simply run bellow command to create:

php artisan make:auth

Step 5: Email Verification Setup

In last step, we need to add email verification setup, so basically we have to add email verification class implement in user model, use middleware for protection. So just update like as bellow files one by one:

app/User.php

<?php

namespace App;

use IlluminateNotificationsNotifiable;

use IlluminateContractsAuthMustVerifyEmail;

use IlluminateFoundationAuthUser 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',

];

}

routes/web.php

Route::get('/', function () {

return view('welcome');

});

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

Route::get('/home', 'HomeController@index')->name('home');

app/Http/Controllers/HomeController.php

<?php

namespace AppHttpControllers;

use IlluminateHttpRequest;

class HomeController extends Controller

{

/**

* Create a new controller instance.

*

* @return void

*/

public function __construct()

{

$this->middleware(['auth','verified']);

}

/**

* Show the application dashboard.

*

* @return IlluminateHttpResponse

*/

public function index()

{

return view('home');

}

}

Now you are ready to run your laravel 5.8 app. So let’s check by following command:

Also see:How to create 404 error page in Laravel 5.8?

php artisan serve

You will find Layout like as bellow screenshot:

Home:

Registration:

Email Alert:

Email:

Success:

I hope you found your best…

Hope this code and post will helped you for implement Laravel 5.8 Email Verification Example. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

8  +  2  =  

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US