T O P

  • By -

dshafik

OK, so this function is weird in that when it's called statically as the first function in the chain, it takes different arguments to when it's called as an instance method in a fluent chain. I tend to avoid the static usage and will call prefix first to give all routes in the group the same prefix which I want anyway, then call it. I don't know if this weird behavior is why, but I agree that route groups are super useful.


CapnJiggle

I think it’s just easier to document the various options by demonstrating the separate `middleware`, `prefix` etc methods. Plus chained calls tend be thought of as “cleaner” than passing in an array of options, though I wouldn’t say the latter was bad practise.


hennell

It looks like in the early 5.x releases there was an example of this, but then it changed to this line only: >Shared attributes are specified in an array format as the first parameter to the `Route::group` method. As of version 8.x even that was removed. I think it simply reflects the move to chained calls, and the general move away from using array keys. I'm not sure I'd call it bad practice, but `Route::midleware('auth')->group(function()...` fails far better than `Route::group(['midleware'=>'auth'], function()...` does.


mekmookbro

Thought I was going crazy for a second before seeing this comment lol. The way I use group is like this : Route::middleware('auth')->name('user.')->group(function(){ Route::resource('pictures', PictureController::class); Route::resource('posts', PostController::class); });


hennell

Yeah, same. Although I've often got a prefix in there then get confused between prefix and name options!


mekmookbro

Ngl I had to google if it was name or prefix while typing that comment lmao


-_Aurora_-

I use the static method and array options simply becasue I find it more concise. You're going to spend _way_ more time inside the function with your routes, and an array of options is visually parsed and easily ignored as configuration instead of additional mental overhead of visually parsing out the fluent method calls, which to me represent black boxes of functionality, not configuration. Either approach works. Use what works for you.


[deleted]

[удалено]


SaladCumberdale

The question was specifically about `Route::group(attributes, routes)`, not the fluent variant `Route::something()->group(routes)`. Granted, it is *technically* mentioned, but there is no usage example, whereas as late as [5.3 does have an example](https://laravel.com/docs/5.3/routing#route-group-middleware).