From 77807ce3b4b0667658779ce84a8e0fdd2e9260d5 Mon Sep 17 00:00:00 2001 From: Abdelmajid Aouby Date: Tue, 18 Feb 2025 11:19:39 +0100 Subject: [PATCH 1/3] Fix routeCollection get method return value when searching by dot notation --- src/Illuminate/Routing/RouteCollection.php | 2 +- tests/Routing/RouteCollectionTest.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Routing/RouteCollection.php b/src/Illuminate/Routing/RouteCollection.php index c5a0ce2e0a0a..58e6daf80e6e 100644 --- a/src/Illuminate/Routing/RouteCollection.php +++ b/src/Illuminate/Routing/RouteCollection.php @@ -171,7 +171,7 @@ public function match(Request $request) */ public function get($method = null) { - return is_null($method) ? $this->getRoutes() : Arr::get($this->routes, $method, []); + return is_null($method) ? $this->getRoutes() : $this->routes[$method] ?? []; } /** diff --git a/tests/Routing/RouteCollectionTest.php b/tests/Routing/RouteCollectionTest.php index c299cc4b0fdb..4fb543df1172 100644 --- a/tests/Routing/RouteCollectionTest.php +++ b/tests/Routing/RouteCollectionTest.php @@ -66,6 +66,24 @@ public function testRouteCollectionCanRetrieveByAction() $this->assertSame($action, $routeIndex->getAction()); } + public function testRouteCollectionCanRetrieveByMethod() + { + $this->routeCollection->add($routeIndex = new Route('GET', 'foo/index', $action = [ + 'uses' => 'FooController@index', + 'as' => 'route_name', + ])); + + $this->assertCount(1, $this->routeCollection->get('GET')); + $this->assertCount(0, $this->routeCollection->get('GET.foo/index')); + $this->assertSame($routeIndex, $this->routeCollection->get('GET')['foo/index']); + + $this->routeCollection->add($routeShow = new Route('GET', 'bar/show', [ + 'uses' => 'BarController@show', + 'as' => 'bar_show', + ])); + $this->assertCount(2, $this->routeCollection->get('GET')); + } + public function testRouteCollectionCanGetIterator() { $this->routeCollection->add(new Route('GET', 'foo/index', [ From 206910554bd93b547c93bf45b5c09433d2bf43f1 Mon Sep 17 00:00:00 2001 From: Abdelmajid Aouby Date: Tue, 18 Feb 2025 11:41:49 +0100 Subject: [PATCH 2/3] remove unused import --- src/Illuminate/Routing/RouteCollection.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Illuminate/Routing/RouteCollection.php b/src/Illuminate/Routing/RouteCollection.php index 58e6daf80e6e..fda1faa81cf1 100644 --- a/src/Illuminate/Routing/RouteCollection.php +++ b/src/Illuminate/Routing/RouteCollection.php @@ -4,7 +4,6 @@ use Illuminate\Container\Container; use Illuminate\Http\Request; -use Illuminate\Support\Arr; class RouteCollection extends AbstractRouteCollection { From 1ab173a4e62dac2b2b90310480ae5382b18a260c Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 18 Feb 2025 09:23:16 -0600 Subject: [PATCH 3/3] Update RouteCollection.php --- src/Illuminate/Routing/RouteCollection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Routing/RouteCollection.php b/src/Illuminate/Routing/RouteCollection.php index fda1faa81cf1..9d6a087204c4 100644 --- a/src/Illuminate/Routing/RouteCollection.php +++ b/src/Illuminate/Routing/RouteCollection.php @@ -170,7 +170,7 @@ public function match(Request $request) */ public function get($method = null) { - return is_null($method) ? $this->getRoutes() : $this->routes[$method] ?? []; + return is_null($method) ? $this->getRoutes() : ($this->routes[$method] ?? []); } /**