Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.6] Passing parameters to Grouped Middleware(s) on Routes middleware setup #25048

Closed
wants to merge 7 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/Illuminate/Routing/Router.php
Expand Up @@ -676,6 +676,25 @@ protected function runRouteWithinStack(Route $route, Request $request)
public function gatherRouteMiddleware(Route $route)
{
$middleware = collect($route->gatherMiddleware())->map(function ($name) {
// try to see if the name contains any middleware parameters
if (is_string($name) && strpos($name, ':') !== false) {
list($main_name, $args) = explode(':', $name);
// check to see if the `$main_name` is part of the middleware groups only
if (array_key_exists($main_name, $this->middlewareGroups)) {
$groups = $this->middlewareGroups[$main_name];
// distribute the middleware parameters to all
// individual middlewares that make up the group
foreach ($groups as $key => $middleware) {
if (! isset($this->middlewareGroups[$middleware])) {
$groups[$key] = "{$middleware}:{$args}";
}
}
// overwrite major group middleware array with modified one
$this->middlewareGroups[$main_name] = $groups;
$name = $main_name;
}
}

return (array) MiddlewareNameResolver::resolve($name, $this->middleware, $this->middlewareGroups);
})->flatten();

Expand Down