laravel-8laravel-routingemail-verificationlaravel-requestlaravel-controller

How to show message to the user after email verification in Laravel?


I want to display a message to the user after email verification. Getting an email to email verification after new user sign up to the website. There is a VerficationController. how I can modify to get the notification?


<?php

namespace App\Http\Controllers\Auth;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\VerifiesEmails;

class VerificationController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Email Verification Controller
    |--------------------------------------------------------------------------
    |
    | This controller is responsible for handling email verification for any
    | user that recently registered with the application. Emails may also
    | be re-sent if the user didn't receive the original email message.
    |
    */

    use VerifiesEmails;

    /**
     * Where to redirect users after verification.
     *
     * @var string
     */
    protected $redirectTo = RouteServiceProvider::HOME;

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
        $this->middleware('signed')->only('verify');
        $this->middleware('throttle:6,1')->only('verify', 'resend');
    }
}



Solution

  • You can override verified function like this.

        protected function verified(Request $request)
    {
        $request->session()->flash('alert','You message here');
    }
    

    when the user will be verified this is will add a session and then where ever you redirecting you can get message from Session and can show message.

    Like this:

    @if(Session::has('alert'))
      <p class="alert {{ Session::get('alert-class', 'alert-info') }}">
        {{ Session::get('alert') }}
      </p>
    @endif