Skip to content

[9.x] Add support for passing array as the second parameter for the group method.#40945

Merged
taylorotwell merged 2 commits intolaravel:9.xfrom
hossein-zare:9.x
Feb 10, 2022
Merged

[9.x] Add support for passing array as the second parameter for the group method.#40945
taylorotwell merged 2 commits intolaravel:9.xfrom
hossein-zare:9.x

Conversation

@hossein-zare
Copy link
Copy Markdown
Contributor

Hi.

What's this PR for? (example):
in the RouteServiceProvider file:

Route::middleware('web')
   ->namespace($this->namespace)
      ->group(base_path('routes/account/web.php'));

Route::middleware('web')
   ->namespace($this->namespace)
      ->group(base_path('routes/account/staff.php'));

can be written as follows

Route::middleware('web')
   ->namespace($this->namespace)
      ->group([
         base_path('routes/account/web.php'),
         base_path('routes/account/staff.php')
       ]);

Both of them with the same middleware and namespace in just an array.

Reasons why this PR won't break other features:

  1. The original group method only accepts \Closure|string as the second parameter which is $routes, so passing an array won't mess around.

    The original group:

    /**
      * Create a route group with shared attributes.
     *
     * @param  array  $attributes
     * @param  \Closure|string  $routes
     * @return void
     */
    public function group(array $attributes, $routes)
  2. It's only one simple commit, I also tested it on a real/ready project.

I ❤ Laravel

@hossein-zare hossein-zare changed the title Support passing array as the second parameter for the group method. [9.x] Add support for passing array as the second parameter for the group method. Feb 10, 2022
@taylorotwell taylorotwell merged commit 97eaa0a into laravel:9.x Feb 10, 2022
@aronpc
Copy link
Copy Markdown

aronpc commented Mar 7, 2022

#28418

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants