Can Slim4 middleware not set before / after for group?

Excuse me for my poor English.
Can Slim4 middleware not set before / after for group?

$app->group('/users/', function (RouteCollectorProxy $group) {
// OK afterfilter
$group->any('{id:[0-9]+}/','RouteClass')->add(new Middleware());

// NG
$group->add(new Middleware())->any('{id:[0-9]+}/','RouteClass');

});

This sample assumes middleware that is added if there is no “/” at the end of the user ID.

However, it seems that only the Before filter can be attached.

Could you teach me

Thank you.

This will add the middleware to a single route

$group->any(‘{id:[0-9]+}/’,‘RouteClass’)->add(new Middleware());

This will add the middleware to the route group and then adds a route.
(The middleware will be added a second time here)

$group->add(new Middleware())->any(‘{id:[0-9]+}/’,‘RouteClass’);

What are you trying to achieve?

I’m using Google Translate, so please forgive me for making mistakes.

$ group-> add (new Middleware ())

In, it is used for pre-filter (redirect when there is no / at the end of URI).

I noticed it while writing.

Is there no prefilter in middleware?

Is there any other way?

For example

/ users / 111

To

/ users / 111 /

To redirect to.

Have you tried this?

http://www.slimframework.com/docs/v4/cookbook/route-patterns.html

Thank you. It was helpful.

But I don’t want to rewrite every URL.
For example, in the following URL, I don’t want to add / after profile.

/ users / 123 / profile