Search code examples
phplaravellaravel-10laravel-jetstream

Resolving the 'Class does not exist' error in Laravel 10


I'm new to Laravel 10, and I recently installed Jetstream. When I run php artisan route:list in the console, I get the following error: Class "verified" does not exist.

I do have verified in my Kernel:

protected $middlewareAliases = [
    ...
    ...
    'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
];

in my route in web.php i have this

Route::group(['middleware' => 'verified', 'web'],function(){
  Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');
});

in jetstream.php there is this 'middleware' => ['auth', 'verified', 'web'],

and this is the error i see on console

   ReflectionException 

  Class "verified" does not exist

  at vendor/laravel/framework/src/Illuminate/Foundation/Console/RouteListCommand.php:225
    221▕             if ($this->isFrameworkController($route)) {
    222▕                 return false;
    223▕             }
    224▕ 
  ➜ 225▕             $path = (new ReflectionClass($route->getControllerClass()))
    226▕                                 ->getFileName();
    227▕         } else {
    228▕             return false;
    229▕         }

      +3 vendor frames 

  4   [internal]:0
      Illuminate\Foundation\Console\RouteListCommand::Illuminate\Foundation\Console\{closure}(Object(Illuminate\Routing\Route))
      +16 vendor frames 

  21  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

I don't know what I'm missing or how to fix this.


Solution

    1. Clear you caches
    php artisan cache:clear
    php artisan route:clear
    php artisan config:clear
    php artisan view:clear
    
    1. Ensure that your Verified middleware is correctly assigned in your routes.
    Route::middleware('verified') - > group(function() {
      // Your routes
    });
    
    1. sometimes the composer autoload files might be out of date. run below command.
    composer dump-autoload