NotFoundHttpException
The requested URL does not match any defined route.
Explanation
NotFoundHttpException is thrown when no route matches the incoming request URL. Unlike ModelNotFoundException which means a route matched but the record wasn't found, this means no route was defined for the URL at all. This commonly happens after changing route definitions, when visiting URLs with incorrect casing, or when route groups have path prefixes you forgot about. Laravel returns a 404 status code by default for this exception.
Common Causes
- Route not defined for the URL
- Incorrect route group prefix
- Stale route cache
- URL casing mismatch
- Routes file not loaded in RouteServiceProvider
Solution
Run php artisan route:list to see all defined routes and verify your URL matches one of them. Check for typos in route definitions and URLs. Ensure route group prefixes are correct. Verify that your routes file is being loaded (check RouteServiceProvider). If the route existed before, check if a cache is stale by running php artisan route:clear. For SPA applications, ensure your catch-all route is defined for client-side routing.
Code Example
// This route doesn't exist, causing NotFoundHttpException
// GET /api/users/profile
// Define the route properly
Route::get('/api/users/profile', [UserController::class, 'profile']);
// For SPAs, add a catch-all route
Route::get('/{any}', function () {
return view('app');
})->where('any', '.*');
// For API versioning, ensure prefix matches
Route::prefix('api/v1')->group(function () {
Route::get('/users', [UserController::class, 'index']);
});
// Must access as /api/v1/users, not /api/users
Error Information
Language
php
Framework
laravel
Difficulty
Beginner
Views
28
Related Errors
Laravel
QueryException (SQL Errors)
A database query failed due to invalid SQL, constraint violations, or connection issues.
Laravel
Laravel Queue Connection Failed
The application cannot connect to the queue driver (Redis, SQS, database, etc.).
Laravel
ReflectionException
A class or method could not be found or instantiated via PHP reflection.
503
DevOps
Service Unavailable (503)
The server is temporarily unable to handle requests due to overload or maintenance.