Skip to content

Commit 98ddaa6

Browse files
[11.x] Fix routeCollection get method return value when searching by dot not… (#54672)
* Fix routeCollection get method return value when searching by dot notation * remove unused import * Update RouteCollection.php --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 013d708 commit 98ddaa6

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/Illuminate/Routing/RouteCollection.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Illuminate\Container\Container;
66
use Illuminate\Http\Request;
7-
use Illuminate\Support\Arr;
87

98
class RouteCollection extends AbstractRouteCollection
109
{
@@ -171,7 +170,7 @@ public function match(Request $request)
171170
*/
172171
public function get($method = null)
173172
{
174-
return is_null($method) ? $this->getRoutes() : Arr::get($this->routes, $method, []);
173+
return is_null($method) ? $this->getRoutes() : ($this->routes[$method] ?? []);
175174
}
176175

177176
/**

tests/Routing/RouteCollectionTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,24 @@ public function testRouteCollectionCanRetrieveByAction()
6666
$this->assertSame($action, $routeIndex->getAction());
6767
}
6868

69+
public function testRouteCollectionCanRetrieveByMethod()
70+
{
71+
$this->routeCollection->add($routeIndex = new Route('GET', 'foo/index', $action = [
72+
'uses' => 'FooController@index',
73+
'as' => 'route_name',
74+
]));
75+
76+
$this->assertCount(1, $this->routeCollection->get('GET'));
77+
$this->assertCount(0, $this->routeCollection->get('GET.foo/index'));
78+
$this->assertSame($routeIndex, $this->routeCollection->get('GET')['foo/index']);
79+
80+
$this->routeCollection->add($routeShow = new Route('GET', 'bar/show', [
81+
'uses' => 'BarController@show',
82+
'as' => 'bar_show',
83+
]));
84+
$this->assertCount(2, $this->routeCollection->get('GET'));
85+
}
86+
6987
public function testRouteCollectionCanGetIterator()
7088
{
7189
$this->routeCollection->add(new Route('GET', 'foo/index', [

0 commit comments

Comments
 (0)