Skip to content

Commit a0e25cd

Browse files
ThorbenGtaylorotwell
authored andcommitted
[5.5] Make Route Macroable (#20970)
* Add Macroable Trait to Route * Add testRouteMacro to RoutingRouteTest * Update Route.php
1 parent a3db80b commit a0e25cd

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/Illuminate/Routing/Route.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Illuminate\Support\Str;
1010
use Illuminate\Http\Request;
1111
use Illuminate\Container\Container;
12+
use Illuminate\Support\Traits\Macroable;
1213
use Illuminate\Routing\Matching\UriValidator;
1314
use Illuminate\Routing\Matching\HostValidator;
1415
use Illuminate\Routing\Matching\MethodValidator;
@@ -18,7 +19,7 @@
1819

1920
class Route
2021
{
21-
use RouteDependencyResolverTrait;
22+
use Macroable, RouteDependencyResolverTrait;
2223

2324
/**
2425
* The URI pattern the route responds to.

tests/Routing/RoutingRouteTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,25 @@ public function testMacro()
308308
$this->assertEquals('OK', $router->dispatch(Request::create('webhook', 'GET'))->getContent());
309309
$this->assertEquals('OK', $router->dispatch(Request::create('webhook', 'POST'))->getContent());
310310
}
311+
312+
public function testRouteMacro()
313+
{
314+
$router = $this->getRouter();
315+
316+
Route::macro('breadcrumb', function ($breadcrumb) {
317+
$this->action['breadcrumb'] = $breadcrumb;
318+
319+
return $this;
320+
});
321+
322+
$router->get('foo', function () {
323+
return 'bar';
324+
})->breadcrumb('fooBreadcrumb')->name('foo');
325+
326+
$router->getRoutes()->refreshNameLookups();
327+
328+
$this->assertEquals('fooBreadcrumb', $router->getRoutes()->getByName('foo')->getAction()['breadcrumb']);
329+
}
311330

312331
public function testClassesCanBeInjectedIntoRoutes()
313332
{

0 commit comments

Comments
 (0)