Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vincej's avatar
Level 15

Can not do a route list

Out of the blue I have a strange error of "Route Not Defined" when it is absolutely defined. I have cleared my cache and cleared the routes. what is more when I attempt to do a route:list I am getting an even more strange error which is preventing me from debugging the Route not defined. the class which is being referenced has not been used in this code in ages since I converted to inertia from api's.

how can I clear the class (?) or what ever is going on when cache:clear is not doing it?

vincejacobs@Vinces-MacBook-Pro KidsClub % php artisan route:list

   ReflectionException 

  Class "App\Http\Controllers\Api\allChildrenController" does not exist

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

      +3 vendor frames 

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

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



0 likes
16 replies
LaryAI's avatar
Level 58

The error message suggests that the class "App\Http\Controllers\Api\allChildrenController" does not exist. To resolve this issue, you can try the following steps:

  1. Make sure that the class "allChildrenController" exists in the specified namespace "App\Http\Controllers\Api". Check if the file containing the class is present in the correct directory.

  2. Verify the spelling and capitalization of the class name. Ensure that it matches the class name used in your routes or other parts of your code.

  3. If you have recently made changes to your code, try running the following command to clear the cached routes:

    php artisan route:clear
    

    This command will clear the cached routes and generate a fresh cache.

  4. If the issue persists, try running the following command to clear the application cache:

    php artisan cache:clear
    

    This command will clear the entire application cache, including any cached classes.

  5. If none of the above steps resolve the issue, check if there are any other references to the "allChildrenController" class in your codebase. It's possible that there might be a reference to the class in a configuration file or a service provider that needs to be updated or removed.

If the problem still persists, it might be helpful to provide more information about your Laravel version, the contents of your routes file, and any relevant code snippets to further diagnose the issue.

Tray2's avatar

In you API routes file, you have defined that you for one or more routes use allChildrenController, Laravel can't find that class. Make sure that it exists, and that you have the proper spelling, and that you have imported it into the routes file.

Class "App\Http\Controllers\Api\allChildrenController" does not exist

Classes should also always start with a capital letter and then use pascal case.

AllChildrenController.php

1 like
vincej's avatar
Level 15

@Tray2 Brilliant! Thank you - I am an idiot. I totally forgot to delete the api route. I can now see the route list.

Now to my core problem. I am getting the Route not defined error, when it is absolutely there in the route list as a generated route

GET|HEAD   Count ..........................generated::xHr6wh2nhIdzqdty`

I have the href listed in my master layout under the Nav

  <a class="link dropdown-item" href="{{route('Count')}}">Max Head Count</a>

And the web.php file has the route listed like this:

Route::view('Count','Count')->name('Count')->middleware('auth');

I have other routes listed in the same drop down also as view with out any trouble.

If I remove the href, the href="{{route('Count')}}> my page loads properly.

Any ideas why I am getting this Route not defined ??

Many Thanks!!

1 like
Tray2's avatar

@vincej The route helper uses the name of the route, not the path of the route.

Route::get('/', [HomeController::class, 'index'])->name('home');

Then you use the name in the route call.

<a href="{{ route('home')}}">Home</a>
Snapey's avatar

whats a generated route? Thats a new one on me

This problem can be due to two routes with the same url. Check you don't have a duplicate /count route. Remember lettercase is irrelevant and good practice is to only use lower case in routes

martinbean's avatar

whats a generated route?

@Snapey That’s when routes are cached, which people shouldn’t be doing locally /cc @vincej

Snapey's avatar

@martinbean oh I see. Its a generated route name when the route does not have a name. I very rarely list routes once they have been cached. Thanks.

mathewwhide's avatar

It appears that the generated route name is assigned when a route lacks a predefined name. In practice, routes are typically cached, so listing them again is infrequent.

Regards

vincej's avatar
Level 15

Guys, Thank you all for jumping in and helping out. I wish I could offer a best answer to @tray2 for reminding me to delete my API calls when using inertia and @martinbean for the caching advise.

I don't know what happened yesterday. I cleared cache, optimized and cleared cleared routes and still I was getting the generated route. Anyway, everything is working again now as expected. Many thanks to all!

1 like
Snapey's avatar

Hi @vincej don't cache any routes or config in development. There is no need to run optimize or route:cache and in fact its risky for your mental well being to use these. Save them for your deployment.

vincej's avatar
Level 15

Hi @Snapey. yeah, after posting my response I realised my mistake, optimize creates a routes cache .... a mistake I'll hard not to make again!

Please or to participate in this conversation.