0

I'm using Laravel 10, and I've been looking for a way to queue verification emails sent by Laravel, I came across this post where they suggested overriding and extending the VerifyEmail class so we can implement ShouldQueue in the new class, but for some reason only when I implement ShouldQueue the queued job fails with this exception :

Symfony\Component\Routing\Exception\RouteNotFoundException: Route [verification.verify] not defined.

here is my code related to this matter:

Models\User.php :

    public function sendEmailVerificationNotification() {
        $this->notify(new QueuedVerifyEmail);
    }

Notifications\QueuedVerifyEmail.php (here if I don't implement ShouldQueue it'll work as normal, slow response)

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Auth\Notifications\VerifyEmail;

class QueuedVerifyEmail extends VerifyEmail implements ShouldQueue
{
    use Queueable;
}

AuthController.php

// sending verification email when registering
    public function register(StoreUserRequest $request) {
        
        $user = User::create($request->all());

        if($user) {
            $token = $user->createToken('api token of ' . $user->name);

            // sending verification mail
            $user->sendEmailVerificationNotification();

            return $this->success([
                'user' => $user,
                'token' => $token
            ], 201, "user created successfully!");
        }else {
            return $this->failed([], 500, $user);
        }
            
    }
// verifying via the sent link
    public function verifyEmail(EmailVerificationRequest $request) {

        if($request->user()->hasVerifiedEmail()) {
            return $this->success([], 208, "already verified!");
        }

        $request->fulfill();
        return $this->success([], 200, "verified!");

    }

routes\api.php

Route::prefix('v1')->group(function() {
    ...
    // email verification
    Route::get('/email/verify/{id}/{hash}', [AuthController::class, 'verifyEmail'])->middleware(['auth:sanctum', 'signed'])->name('verification.verify');
});

route list

GET|HEAD   / .................................................................. 
  POST       _ignition/execute-solution ignition.executeSolution › Spatie\Larave… 
  GET|HEAD   _ignition/health-check ignition.healthCheck › Spatie\LaravelIgnitio… 
  POST       _ignition/update-config ignition.updateConfig › Spatie\LaravelIgnit… 
  GET|HEAD   sanctum/csrf-cookie sanctum.csrf-cookie › Laravel\Sanctum › CsrfCoo… 
  GET|HEAD   v1/address .............................. v1\AddressController@index 
  POST       v1/address .............................. v1\AddressController@store 
  DELETE     v1/address/{address} .................. v1\AddressController@destroy 
  PATCH      v1/address/{address} ................... v1\AddressController@update 
  GET|HEAD   v1/admin/get-c-a ........................ v1\ClientsController@getCA 
  GET|HEAD   v1/client ............................... v1\ClientsController@index 
  POST       v1/client ............................... v1\ClientsController@store 
  PATCH      v1/client/{client} ..................... v1\ClientsController@update 
  GET|HEAD   v1/email/verify/{id}/{hash} verification.verify › v1\AuthController… 
  GET|HEAD   v1/users .................................. v1\UsersController@index 
  POST       v1/users/login ............................. v1\AuthController@login 
  GET|HEAD   v1/users/logout ........................... v1\AuthController@logout 
  GET|HEAD   v1/users/logout-all .................... v1\AuthController@logoutAll 
  POST       v1/users/register ....................... v1\AuthController@register

I'm very new to Laravel, so if you have any better way to queue the verification emails please do let me know.

anas ali
  • 23
  • 6
  • 2
    the main problem in your case this route not exist ( verification.verify ) try to find this route in your route list ( php artisan route:list ) – Mohamed Ahmed Jul 01 '23 at 02:32
  • @MohamedAhmed I added the route list to the post, should've done that earlier sorry, the problem is that it works totally fine when I delete the `implements ShouldQueue` in "QueuedVerifyEmail.php" file – anas ali Jul 01 '23 at 18:16

1 Answers1

0

so after I got tired of banging my head for the day I closed it and came the next day and it works now.. soo I guess I forgot to implement the number one troubleshooting rule of technology, turn it off then turn it on again.

something didn't propagate while configuring files and restarting the php artisan serve command fixed it.

anas ali
  • 23
  • 6