I like to group my routes by namespace, prefix etc. to make the routes file modular and not too overwhelming. I recently began writing an API in Laravel and discovered Lumen so decided to port it over.
I had already begun organising my API routes using groups and found when transferring them to Lumen, the group attributes weren't being merged with the parent group's attributes.
Looking under the hood, the group method of the Application class does indeed skip the merging process which overwrites the parent attributes. Although this may be an intended change, in the documentation, nested namespaces are used http://lumen.laravel.com/docs/routing#route-group-namespaces
So my question is, which is wrong; the group method or the documentation? And in any case should this issue be raised or does someone know something?
@thomaskim Okay, thanks for sending that pull request.
I was thinking of creating an extension to the Lumen Application that uses the group stack implementation used in Laravel's Router. What are your thoughts on that?
This is what I've come up with, works very nicely.
use Closure;
use Illuminate\Routing\Router;
use Laravel\Lumen;
class Application extends Lumen\Application
{
public function group(array $attributes, Closure $callback)
{
$router = app(Router::class);
$attributes = $router->mergeGroup($attributes, (array) $this->groupAttributes);
parent::group($attributes, $callback);
}
}