Black Friday: coupon FRIDAY24 for 40% off Yearly/Lifetime membership! Read more here

Laravel: "Route not defined": Easiest Way to Fix

If you build links and call them by route names, you may get an error like "Route [register] not defined". But you could swear that the name is correct! I will show you the easiest way to debug and fix it.

This is the error I'm talking about:

In this case, you go to your routes file and clearly see that the route is called "register"!

routes/auth.php:

Route::get('register',
[RegisteredUserController::class, 'create'])
->name('register');

What you may be missing is that route may be in a group that adds a prefix to the name. The tricky part is that group may be defined in various places:

  • In the same Routes file
  • In a different Routes file that includes the current file
  • Or, even in RouteServiceProvider globally

So, how to debug?

Easy. Go to Terminal and type:

php artisan route:list

It will show you all the routes in your project, and if you find "register", you may find that the real full route name is auth.register:

If you have a big project and you're struggling to find your route in the list, you may filter it:

php artisan route:list --name=register

Now, you may try to find the file that contains the prefix('auth'):

Route::middleware('guest')
->prefix('auth')
->as('auth.')
->group(function () {
 
// ... many other routes in that group ...
 
Route::get('register',
[RegisteredUserController::class, 'create'])
->name('register');

But in this case, the real solution is to actually fix the name of your route wherever you call it: from route('register') to route('auth.register').

No comments or questions yet...

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 67 courses (1172 lessons, total 43 h 18 min)
  • 90 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord

Recent New Courses