Get Current Route Group Name

Hello,

I want to access the current route’s group name. For example, I have routes like this:

$app->group('/admin', function () use ($container) {
    $this->get('/books', BookController::class . ':index')->setName('admin.books.index');
    $this->get('/movies', MovieController::class . ':index')->setName('admin.movies.index');
})->add(new ExampleMiddleware($container));

In this example, I want to get current route’s group which is /admin in ExampleMiddleware.

How can I do this?

Retrieving Current Route

$route = $request->getAttribute('route');

    if (empty($route)) {
        throw new NotFoundException($request, $response);
    }

    $name = $route->getName();
    $groups = $route->getGroups();
    $methods = $route->getMethods();
    $arguments = $route->getArguments();

Thanks, @Mikalay. I tried this. But it didn’t help.