From 9801e0a4ca12656c307f8b3b6c5e01842dd3ad7a Mon Sep 17 00:00:00 2001 From: Hunter Skrasek Date: Wed, 30 Apr 2014 22:30:06 -0500 Subject: [PATCH 1/2] Override the Illuminate\Router getRoutes() command to re-add API Routes to the artisan routes command. --- src/Routing/Router.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Routing/Router.php b/src/Routing/Router.php index dc91c3b0e..c6418be5e 100644 --- a/src/Routing/Router.php +++ b/src/Routing/Router.php @@ -663,4 +663,16 @@ public function getInspector() return $this->inspector ?: $this->inspector = new ControllerInspector; } + public function getRoutes() + { + $routes = parent::getRoutes(); + + foreach($this->api as $apiRoutes) { + foreach($apiRoutes->getRoutes() as $apiRoute) { + $routes->add($apiRoute); + } + } + + return $routes; + } } From 0cbf995eef3c8bc13a72b0d5a1c4ec832a2764f2 Mon Sep 17 00:00:00 2001 From: Hunter Skrasek Date: Wed, 30 Apr 2014 22:42:06 -0500 Subject: [PATCH 2/2] Test to make sure the overridden getRoutes() returns the correct amount of routes, when both API routes and normal routes are added to the Router --- tests/RoutingRouterTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/RoutingRouterTest.php b/tests/RoutingRouterTest.php index 6e2ee5fad..116ad537a 100644 --- a/tests/RoutingRouterTest.php +++ b/tests/RoutingRouterTest.php @@ -429,5 +429,11 @@ public function testRouterDefaultsToDefaultVersionCollectionWhenNoAcceptHeader() $this->assertEquals('{"message":"baz"}', $this->router->dispatch($request)->getContent()); } + public function testRouterReturnsCorrectRoutesForArtisanCommand() + { + $this->router->api(['version' => 'v1'], function() { $this->router->get('foo', function() { return 'bar'; }); }); + $this->router->get('bar', function() { return 'baz'; }); + $this->assertCount(2, $this->router->getRoutes()); + } }