Skip to content

[11.x] Fix routeCollection get method return value when searching by dot not…#54672

Merged
taylorotwell merged 3 commits into
laravel:11.xfrom
abdel-aouby:fix/routeCollection-get-method-return-value
Feb 18, 2025
Merged

[11.x] Fix routeCollection get method return value when searching by dot not…#54672
taylorotwell merged 3 commits into
laravel:11.xfrom
abdel-aouby:fix/routeCollection-get-method-return-value

Conversation

@abdel-aouby

Copy link
Copy Markdown
Contributor

Changes

  • Remove the use of Arr::get($this->routes, $method, []) from the get method in \Illuminate\Routing\RouteCollection::get because it allows to return a route object when searching with "dot" notation. despite the method name, parameter, and PHPDoc indicating that the search is performed by $method (e.g GET , POST ...) and should return array of Route objects when found

Changes
as described and discussed in #54541

  • The current implementation of the get method in \Illuminate\Routing\RouteCollection::get has a side effect that allows us to search by "dot" notation
    example: $this->routeCollectionget->('GET.foo/index'); will return an object instance of Route (not array)
    which contradict:
  1. The parameter name ($method)
  2. The phpDoc that says it should return \Illuminate\Routing\Route[] and not \Illuminate\Routing\Route object as it is in this case

Solution

  • Eliminate the side effect by removing the search by "dot" notation that is provided by Arr::get() and use null-coalescing operator instead to perform a search on the routes collection (first level that contains the methods)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants