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 #45191

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/Illuminate/Routing/AbstractRouteCollection.php
Original file line number Diff line number Diff line change
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,24 +104,26 @@ protected function getRouteForMethods($request, array $methods)
}))->bind($request);
}

$this->methodNotAllowed($methods, $request->method());
$this->methodNotAllowed($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 methodNotAllowed(array $others, $method)
protected function methodNotAllowed($request, array $others, $method)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change to the method signature.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can have two of them. One for the old behaviour and one for the new behaviour.

{
throw new MethodNotAllowedHttpException(
$others,
sprintf(
'The %s method is not supported for this route. Supported methods: %s.',
'The %s method is not supported for route %s. Supported methods: %s.',
$request->path(),
$method,
implode(', ', $others)
)
Expand Down