From 43a8784b2c2368df93946626a188c69c214077df Mon Sep 17 00:00:00 2001 From: Thorben Grahlmann Date: Mon, 4 Sep 2017 14:48:16 +0200 Subject: [PATCH 1/3] Add Macroable Trait to Route --- src/Illuminate/Routing/Route.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Routing/Route.php b/src/Illuminate/Routing/Route.php index 55ea07f258f8..cfe41d185dc8 100755 --- a/src/Illuminate/Routing/Route.php +++ b/src/Illuminate/Routing/Route.php @@ -9,6 +9,7 @@ use Illuminate\Support\Str; use Illuminate\Http\Request; use Illuminate\Container\Container; +use Illuminate\Support\Traits\Macroable; use Illuminate\Routing\Matching\UriValidator; use Illuminate\Routing\Matching\HostValidator; use Illuminate\Routing\Matching\MethodValidator; @@ -18,7 +19,7 @@ class Route { - use RouteDependencyResolverTrait; + use RouteDependencyResolverTrait, Macroable; /** * The URI pattern the route responds to. From 037bdd1a89486ccfabc2152610b69b398814d5fe Mon Sep 17 00:00:00 2001 From: Thorben Grahlmann Date: Mon, 4 Sep 2017 14:50:27 +0200 Subject: [PATCH 2/3] Add testRouteMacro to RoutingRouteTest --- tests/Routing/RoutingRouteTest.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/Routing/RoutingRouteTest.php b/tests/Routing/RoutingRouteTest.php index 319b27164335..e43e7f3b530f 100644 --- a/tests/Routing/RoutingRouteTest.php +++ b/tests/Routing/RoutingRouteTest.php @@ -308,6 +308,25 @@ public function testMacro() $this->assertEquals('OK', $router->dispatch(Request::create('webhook', 'GET'))->getContent()); $this->assertEquals('OK', $router->dispatch(Request::create('webhook', 'POST'))->getContent()); } + + public function testRouteMacro() + { + $router = $this->getRouter(); + + Route::macro('breadcrumb', function ($breadcrumb) { + $this->action['breadcrumb'] = $breadcrumb; + + return $this; + }); + + $router->get('foo', function () { + return 'bar'; + })->breadcrumb('fooBreadcrumb')->name('foo'); + + $router->getRoutes()->refreshNameLookups(); + + $this->assertEquals('fooBreadcrumb', $router->getRoutes()->getByName('foo')->getAction()['breadcrumb']); + } public function testClassesCanBeInjectedIntoRoutes() { From f6dae579d05f0ce652fee777a5ffbf0b84c358bd Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 4 Sep 2017 08:53:25 -0500 Subject: [PATCH 3/3] Update Route.php --- src/Illuminate/Routing/Route.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Routing/Route.php b/src/Illuminate/Routing/Route.php index cfe41d185dc8..0f0823d35798 100755 --- a/src/Illuminate/Routing/Route.php +++ b/src/Illuminate/Routing/Route.php @@ -19,7 +19,7 @@ class Route { - use RouteDependencyResolverTrait, Macroable; + use Macroable, RouteDependencyResolverTrait; /** * The URI pattern the route responds to.