Skip to content

Commit

Permalink
Merge pull request #12911 from themsaid/unique-middlewares
Browse files Browse the repository at this point in the history
[5.2] Apply a middleware only once
  • Loading branch information
taylorotwell committed Mar 29, 2016
2 parents 54d6ff4 + 185447c commit 54bbfb5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Routing/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ public function middleware($middleware = null)
$middleware = [$middleware];
}

$this->action['middleware'] = array_merge(
$this->action['middleware'] = array_unique(array_merge(
(array) Arr::get($this->action, 'middleware', []), $middleware
);
));

return $this;
}
Expand Down
14 changes: 14 additions & 0 deletions tests/Routing/RoutingRouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,20 @@ public function testRouteMiddlewareMergeWithMiddlewareAttributesAsStrings()
);
}

public function testRouteMiddlewareAppliedOnlyOnce()
{
$router = $this->getRouter();
$router->group(['middleware' => 'foo'], function () use ($router) {
$router->get('bar', function () { return 'hello'; })->middleware(['foo', 'foo']);
});
$routes = $router->getRoutes()->getRoutes();
$route = $routes[0];
$this->assertEquals(
['foo'],
$route->middleware()
);
}

public function testRoutePrefixing()
{
/*
Expand Down

0 comments on commit 54bbfb5

Please sign in to comment.