diff --git a/src/Illuminate/Routing/Route.php b/src/Illuminate/Routing/Route.php index f59b47ce032d..ba148d3c1d1e 100755 --- a/src/Illuminate/Routing/Route.php +++ b/src/Illuminate/Routing/Route.php @@ -17,6 +17,7 @@ use Illuminate\Routing\Matching\UriValidator; use Illuminate\Support\Arr; use Illuminate\Support\Str; +use Illuminate\Support\Traits\Conditionable; use Illuminate\Support\Traits\Macroable; use InvalidArgumentException; use Laravel\SerializableClosure\SerializableClosure; @@ -27,7 +28,7 @@ class Route { - use CreatesRegularExpressionRouteConstraints, FiltersControllerMiddleware, Macroable, ResolvesRouteDependencies; + use Conditionable, CreatesRegularExpressionRouteConstraints, FiltersControllerMiddleware, Macroable, ResolvesRouteDependencies; /** * The URI pattern the route responds to. diff --git a/tests/Routing/RoutingRouteTest.php b/tests/Routing/RoutingRouteTest.php index bb7964a7b07b..9caddf307069 100644 --- a/tests/Routing/RoutingRouteTest.php +++ b/tests/Routing/RoutingRouteTest.php @@ -943,6 +943,26 @@ public function testWherePatternsProperlyFilter() }); $route->where('bar', '[0-9]+'); $this->assertFalse($route->matches($request)); + + /* + * Conditional + */ + $route = new Route('GET', '{subdomain}.awesome.test', function () { + // + }); + + $route->when(true, function ($route) { + $route->whereIn('subdomain', [ + 'one', + 'two', + ]); + }); + + $request = Request::create('test.awesome.test', 'GET'); + $this->assertFalse($route->matches($request)); + + $request = Request::create('one.awesome.test', 'GET'); + $this->assertTrue($route->matches($request)); } public function testRoutePrefixParameterParsing()