{"id":1203,"date":"2024-08-07T10:56:44","date_gmt":"2024-08-07T10:56:44","guid":{"rendered":"https:\/\/www.appfinz.com\/blogs\/?p=1203"},"modified":"2025-05-15T04:52:06","modified_gmt":"2025-05-15T04:52:06","slug":"how-to-make-email-verifications-in-laravel","status":"publish","type":"post","link":"https:\/\/www.appfinz.com\/blogs\/how-to-make-email-verifications-in-laravel\/","title":{"rendered":"How to make Email Verifications in Laravel"},"content":{"rendered":"\n<p>Hello Artisans, In this blog we will see how to implement Email Verifications in Laravel, How Email Verification works with Laravel Application, We will use <strong>laravel Breeze<\/strong> package to implement Email Verifications in Laravel Application, To implement email verification in Laravel, follow these steps:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Set Up Your Laravel Project<\/h3>\n\n\n\n<p>If you don&#8217;t have a Laravel project yet, create one:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">composer create-project --prefer-dist laravel\/laravel laravel-email-verification<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Set Up Authentication<\/h3>\n\n\n\n<p>Install <a href=\"https:\/\/github.com\/laravel\/breeze\">Laravel Breeze<\/a> or <a href=\"https:\/\/jetstream.laravel.com\/\">Laravel Jetstream<\/a> for authentication scaffolding. Here, we&#8217;ll use Laravel Breeze:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">composer require laravel\/breeze --dev\nphp artisan breeze:install\nphp artisan migrate\nnpm install &amp;&amp; npm run dev<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Configure Email Settings<\/h3>\n\n\n\n<p>Set up your email configuration in the <code>.env<\/code> file. Add your SMTP server details:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">MAIL_MAILER=smtp\nMAIL_HOST=smtp.mailtrap.io\nMAIL_PORT=2525\nMAIL_USERNAME=your_username\nMAIL_PASSWORD=your_password\nMAIL_ENCRYPTION=tls\nMAIL_FROM_ADDRESS=noreply@example.com\nMAIL_FROM_NAME=&quot;${APP_NAME}&quot;\n<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Step 4: Enable Email Verification<\/h3>\n\n\n\n<p>In your <code>User<\/code> model (<code>app\/Models\/User.php<\/code>), make sure the <code>MustVerifyEmail<\/code> interface is implemented:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">use Illuminate\\Contracts\\Auth\\MustVerifyEmail;\n\nclass User extends Authenticatable implements MustVerifyEmail\n{\n    \/\/ other model methods and properties\n}\n<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Step 5: Update Auth Routes<\/h3>\n\n\n\n<p>In <code>routes\/web.php<\/code>, add the following route to handle email verification:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">use Illuminate\\Foundation\\Auth\\EmailVerificationRequest;\nuse Illuminate\\Http\\Request;\n\nRoute::get('\/email\/verify', function () {\n    return view('auth.verify-email');\n})-&gt;middleware('auth')-&gt;name('verification.notice');\n\nRoute::get('\/email\/verify\/{id}\/{hash}', function (EmailVerificationRequest $request) {\n    $request-&gt;fulfill();\n\n    return redirect('\/home');\n})-&gt;middleware(['auth', 'signed'])-&gt;name('verification.verify');\n\nRoute::post('\/email\/verification-notification', function (Request $request) {\n    $request-&gt;user()-&gt;sendEmailVerificationNotification();\n\n    return back()-&gt;with('message', 'Verification link sent!');\n})-&gt;middleware(['auth', 'throttle:6,1'])-&gt;name('verification.send');\n<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Step 6: Create Email Verification View<\/h3>\n\n\n\n<p>Create a new view file for the email verification notice at <code>resources\/views\/auth\/verify-email.blade.php<\/code>:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">@extends('layouts.app')\n\n@section('content')\n&lt;div&gt;\n    @if (session('message'))\n        &lt;div&gt;\n            {{ session('message') }}\n        &lt;\/div&gt;\n    @endif\n\n    &lt;div&gt;\n        Before proceeding, please check your email for a verification link.\n        If you did not receive the email, click the button below to request another.\n    &lt;\/div&gt;\n\n    &lt;form method=&quot;POST&quot; action=&quot;{{ route('verification.send') }}&quot;&gt;\n        @csrf\n        &lt;button type=&quot;submit&quot;&gt;Resend Verification Email&lt;\/button&gt;\n    &lt;\/form&gt;\n&lt;\/div&gt;\n@endsection\n<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Step 7: Modify Registration Controller<\/h3>\n\n\n\n<p>Make sure your registration controller sends a verification email after a user registers. In the <code>RegisteredUserController<\/code> (or wherever your registration logic is):<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">use Illuminate\\Auth\\Events\\Registered;\n\npublic function store(Request $request)\n{\n    \/\/ validate and create user\n    $user = User::create([\n        'name' =&gt; $request-&gt;name,\n        'email' =&gt; $request-&gt;email,\n        'password' =&gt; Hash::make($request-&gt;password),\n    ]);\n\n    event(new Registered($user));\n\n    Auth::login($user);\n\n    return redirect()-&gt;route('verification.notice');\n}\n<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Step 8: Protect Routes<\/h3>\n\n\n\n<p>Ensure that your application routes are protected and only accessible to verified users. Use the <code>verified<\/code> middleware in <code>routes\/web.php<\/code>:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">Route::get('\/home', [HomeController::class, 'index'])-&gt;middleware(['auth', 'verified'])-&gt;name('home');\n<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Step 9: Test Email Verification<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Register a new user through your registration form.<\/li>\n\n\n\n<li>Check the registered user&#8217;s email for the verification link.<\/li>\n\n\n\n<li>Click the verification link to verify the email.<\/li>\n\n\n\n<li>Ensure the user is redirected to the intended page after verification.<\/li>\n<\/ol>\n\n\n\n<p><strong>I hope this blog will help you to build Make Email Verifications in Laravel<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Also Read: <\/h3>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><a href=\"https:\/\/www.appfinz.com\/blogs\/login-with-api-using-laravel-11\/\"><strong>User Login with API Using Laravel 11<\/strong><\/a><\/p>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><a href=\"https:\/\/www.appfinz.com\/blogs\/how-to-solve-500-internal-server-error-in-laravel\/\"><strong>solve 500 internal server error in laravel<\/strong><\/a><\/p>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong><a href=\"https:\/\/www.appfinz.com\/blogs\/paypal-payment-gateway-integration-in-laravel-11\/\">Paypal Payment Gateway Integration in Laravel 11<\/a><\/strong><\/p>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><a href=\"https:\/\/www.appfinz.com\/blogs\/contact-form-in-laravel-7\/\"><strong>Laravel 9 Contact Form Example Tutorial<\/strong><\/a><\/p>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong><a href=\"https:\/\/www.appfinz.com\/blogs\/laravel-middleware-for-auth-admin-users-roles\/\">Laravel Middleware for Auth Admin Users Roles<\/a><\/strong><\/p>\n\n\n\n<p>If you\u2019re planning to revamp your online presence, don\u2019t miss exploring our\u00a0<a href=\"https:\/\/www.appfinz.com\/website-designing-company-in-delhi\"><strong>website designing services<\/strong><\/a>\u00a0and custom\u00a0<strong><a href=\"https:\/\/www.appfinz.com\/website-development-company-in-delhi\">website development<\/a><\/strong>\u00a0solutions tailored to your business needs.<\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Hello Artisans, In this blog we will see how to implement Email Verifications in Laravel,<\/p>\n","protected":false},"author":1,"featured_media":1211,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[193,191,194,192],"class_list":["post-1203","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-email-verification-method-in-laravel","tag-email-verifications-in-laravel","tag-how-to-integrate-email-verification-method-in-laravel","tag-laravel-email-verification"],"_links":{"self":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts\/1203","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/comments?post=1203"}],"version-history":[{"count":3,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts\/1203\/revisions"}],"predecessor-version":[{"id":1348,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts\/1203\/revisions\/1348"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/media\/1211"}],"wp:attachment":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/media?parent=1203"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/categories?post=1203"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/tags?post=1203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}