-
-
Notifications
You must be signed in to change notification settings - Fork 70
Open
Description
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:
POST /practices/1/submit
-
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels