Summary
RouteBuilder currently breaks when chaining multiple post-group modifiers on the same group result.
Example pattern:
$route->group('auth', function ($route) {
// routes...
})->rateLimit(60, 60)->middlewares(['Auth']);
The second call throws:
rateLimit() must be called inside a group or after a route definition
(or analogous error depending on call order).
Root cause
RouteBuilder stores grouped routes in lastGroupRoutes, but each post-group modifier method consumes/clears this state after one call. As a result, chaining a second post-group modifier has no active group context.
Affected methods:
middlewares()
rateLimit()
cacheable()
Expected behavior
Post-group modifiers should be chainable and order-independent for the same group result.
Both should work:
->middlewares(...)->rateLimit(...)
->rateLimit(...)->middlewares(...)
(and with cacheable(...) combinations)
Scope
Core router fix in RouteBuilder + regression tests.
Acceptance criteria
- Chaining multiple post-group modifiers on one group no longer throws.
- All affected modifier combinations apply to the same grouped routes.
- Add regression tests covering:
- group + middlewares + rateLimit (both orders)
- group + cacheable + one of the above
- Existing route/group behavior remains unchanged for non-chained usage.
Note
This bug is currently blocking natural fluent usage in module templates and can surface during app boot when generated routes include chained post-group modifiers.
Summary
RouteBuildercurrently breaks when chaining multiple post-group modifiers on the same group result.Example pattern:
The second call throws:
rateLimit() must be called inside a group or after a route definition(or analogous error depending on call order).
Root cause
RouteBuilderstores grouped routes inlastGroupRoutes, but each post-group modifier method consumes/clears this state after one call. As a result, chaining a second post-group modifier has no active group context.Affected methods:
middlewares()rateLimit()cacheable()Expected behavior
Post-group modifiers should be chainable and order-independent for the same group result.
Both should work:
->middlewares(...)->rateLimit(...)->rateLimit(...)->middlewares(...)(and with
cacheable(...)combinations)Scope
Core router fix in
RouteBuilder+ regression tests.Acceptance criteria
Note
This bug is currently blocking natural fluent usage in module templates and can surface during app boot when generated routes include chained post-group modifiers.