Back to Error Center

Route [X] not defined

Error Message

Route [posts.show] not defined

Cause

Trying to generate a URL for a named route that doesn't exist. The route may not be defined, or the route name is misspelled.

Solution

Run php artisan route:list to see all defined routes. Check the route definition and name. Ensure route files are loaded.

Code Example

Fix
// Check defined routes
php artisan route:list --name=posts

// Verify route definition
Route::get('/posts/{post}', [PostController::class, 'show'])
    ->name('posts.show'); // Name must match

// Generate URL
url(route('posts.show', $post->id));

Debugging Steps

  1. Run php artisan route:list
  2. Search for the route name in route files
  3. Check for typos in the route name string
  4. Verify the route file is included in the application

Prevention

Use route() helper consistently. Define route names when registering routes. Use IDE plugins for route name autocompletion.