Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Improved error logging for unmatched routes and route not found #45206

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 29 additions & 2 deletions src/Illuminate/Routing/AbstractRouteCollection.php
Expand Up @@ -41,7 +41,10 @@ protected function handleMatchedRoute(Request $request, $route)
return $this->getRouteForMethods($request, $others);
}

throw new NotFoundHttpException;
throw new NotFoundHttpException(sprintf(
'The route %s could not be found.',
$request->path()
));
}

/**
Expand Down Expand Up @@ -101,7 +104,30 @@ protected function getRouteForMethods($request, array $methods)
}))->bind($request);
}

$this->methodNotAllowed($methods, $request->method());
$this->requestMethodNotAllowed($request, $methods, $request->method());
}

/**
* Throw a method not allowed HTTP exception.
*
* @param \Illuminate\Http\Request $request
* @param array $others
* @param string $method
* @return void
*
* @throws \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
*/
protected function requestMethodNotAllowed($request, array $others, $method)
{
throw new MethodNotAllowedHttpException(
$others,
sprintf(
'The %s method is not supported for route %s. Supported methods: %s.',
$request->path(),
$method,
implode(', ', $others)
)
);
}

/**
Expand All @@ -110,6 +136,7 @@ protected function getRouteForMethods($request, array $methods)
* @param array $others
* @param string $method
* @return void
* @deprecated use requestMethodNotAllowed
*
* @throws \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
*/
Expand Down