15

I am trying to implement email verification in Laravel 5.7. I have implemented MustVerifyEmail on User model.

class User extends Authenticatable implements MustVerifyEmail 
{ 
}

But after registration I got this error Route [verification.verify] not defined.

What I am missing in this? Please guide?

Christian Gallarmin
  • 660
  • 4
  • 15
  • 34
hezuxit
  • 151
  • 1
  • 1
  • 3

6 Answers6

15

You are missing Auth::routes(['verify' => true]) in Routes\Web.php.

I suggest watch this video, where it has explained in detail how email verification works in Laravel 5.7.

https://www.youtube.com/watch?v=dbmox3tgI2k

Harish Kumar
  • 218
  • 1
  • 7
  • 1
    the docs seems to assume the reader already know where to place `Auth::routes(['verify' => true])` at. https://laravel.com/docs/5.7/verification#verification-routing – lasec0203 Dec 25 '18 at 21:21
3

What really happens:

Route::middleware(['auth:sanctum', 'verified'])->get('/dashboard', function () {

(['auth:sanctum', 'verified']

when passing two arguments of laravel one of authentication and the other of verification of mail. It says: it is authenticated. and verified ok response: Respond that the user in the table: User email_verified_at is not registered on the email activation date, that is, it has not told me that the email exists. ps passes an exception for that there is a page that you must active as a response to this ... that is, as a response to this ... Your email is not verified even if the page is created either in vue on blade or in limewire in the auth folder.

in App\Models\User search

 // use Illuminate\Contracts\Auth\MustVerifyEmail;

active:

use Illuminate\Contracts\Auth\MustVerifyEmail;

eh implements

class User extends Authenticatable implements MustVerifyEmail

now many things are missing .. We verify that kernel is active the following parameters :

in route App\Http\Kernel.php

// 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,

change:

'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,

in the folder Config: config\fortify.php this:

    // Features::emailVerification(),

it

    Features::emailVerification(),

And the most important of this authentication hell .. the routes: You can do the different types of routes you choose ... but one according to your resources or project.

basic:

Route::middleware(['auth:sanctum'])->get('/dashboard', function () {
        return Inertia::render('Dashboard');
})->middleware('verified')->name('dashboard');

Route::middleware(['auth:sanctum','verified'])->get('/dashboard', function () {
        return Inertia::render('Dashboard');
})->name('dashboard');

a little adrenaline:

Route::group(["middleware" => ['auth:sanctum','verified']], function () {
    Route::get('/dashboard', function () {
        return Inertia::render('Dashboard');
        // return "hola william";
    })->name('dashboard');
    //aca puedes segir colocando las paginas o recursos que quieres cargar mientras en usuario este autenticado y verificado...
});

where does the error come from: Route [verification.verify] not defined

this route/file.. vendor\laravel\framework\src\illuminate\Auth\Middleware\EnsureEmailsVerified.php

function:

    public function handle($request, Closure $next, $redirectToRoute = null)
{
    if (! $request->user() ||
        ($request->user() instanceof MustVerifyEmail &&
        ! $request->user()->hasVerifiedEmail())) {
        return $request->expectsJson()
                ? abort(403, 'Your email address is not verified.')
                : Redirect::guest(URL::route($redirectToRoute ?: 'verification.notice'));
    }

    return $next($request);
}

linea:

: Redirect::guest(URL::route($redirectToRoute ?: 'verification.notice'));

Thank you and success in your projects with laravel. and sorry if I wrote something wrong.

2

Run:

php artisan optimize:clear

It will clear your cache.

Jsowa
  • 9,104
  • 5
  • 56
  • 60
1

In routes/web.php file, add following piece of code:

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

Ref: https://laravel.com/docs/5.7/verification#verification-routing

Nahid
  • 2,911
  • 1
  • 20
  • 17
0

In routes/web.php ensure Auth::routes(['verify' => true]); Then run :

php artisan route:cache

to clear cached routed and update incoming changes

0

You can remove 'verified' middleware, for example:

<?php

Route::middleware(['auth', 'verified'])
    ->group(function(){

     ...

});

?>

Try it, should solve the problem

Ivan Fretes
  • 668
  • 7
  • 11