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
- Run php artisan route:list
- Search for the route name in route files
- Check for typos in the route name string
- 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.