Describe the bug
When defining a dynamic route (/{id:\d+}) inside a route group that uses middleware, the middleware is not executed.
Static routes inside the same middleware group work correctly.
For example:
/user/profile → middleware executes correctly
/practices/1/submit (static route) → middleware executes correctly
/practices/{id:\d+}/submit (dynamic route) → middleware does not execute
The request goes directly to the controller method without passing through the middleware.
To Reproduce
- Define a middleware (example:
auth) that logs or validates authentication.
- Create a route group with middleware:
$app->group('/', [
'middleware' => 'auth',
function () use ($app) {
$app->get('/user/profile', function () {
return response()->json(['message' => 'profile']);
});
$app->post('/practices/{id:\d+}/submit', function () {
return response()->json(['message' => 'submitted']);
});
}
]);
- Register middleware:
$app->registerMiddleware('auth', function () {
error_log("Auth middleware called");
});
- Send request:
-
Observe that middleware is not executed.
-
Replace dynamic route with static:
$app->post('/practices/1/submit', ...);
- Middleware executes correctly.
Expected behavior
Middleware should execute for dynamic routes inside a group the same way it does for static routes.
The dynamic route /practices/{id:\d+}/submit should trigger the auth middleware before reaching the controller.
Additional context
- Leaf version: "leafs/leaf": "^4.4"
- PHP version: PHP 7.4.30
- Server environment: XAMP
This issue only occurs with dynamic parameters inside grouped routes using middleware. Static routes inside the same group work as expected.
Describe the bug
When defining a dynamic route (
/{id:\d+}) inside a route group that uses middleware, the middleware is not executed.Static routes inside the same middleware group work correctly.
For example:
/user/profile→ middleware executes correctly/practices/1/submit(static route) → middleware executes correctly/practices/{id:\d+}/submit(dynamic route) → middleware does not executeThe request goes directly to the controller method without passing through the middleware.
To Reproduce
auth) that logs or validates authentication.Observe that middleware is not executed.
Replace dynamic route with static:
Expected behavior
Middleware should execute for dynamic routes inside a group the same way it does for static routes.
The dynamic route
/practices/{id:\d+}/submitshould trigger theauthmiddleware before reaching the controller.Additional context
This issue only occurs with dynamic parameters inside grouped routes using middleware. Static routes inside the same group work as expected.