13
votes

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?

7

7 Answers

30
votes

Laravel includes the Auth\VerificationController class that contains the necessary logic to send verification links and verify emails. To register the necessary routes for this controller, pass the verify option to the Auth::routes method:

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

You can read more information here : https://laravel.com/docs/5.7/verification

14
votes

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

1
votes

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

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

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

1
votes

Run:

php artisan optimize:clear

It will clear your cache.

1
votes

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.

0
votes

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

php artisan route:cache

to clear cached routed and update incoming changes

0
votes

You can remove 'verified' middleware, for example:

<?php

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

     ...

});

?>

Try it, should solve the problem