Skip to content

can() method does not work for route groups #55114

@marian-r

Description

@marian-r

Laravel Version

11.44.2

PHP Version

8.3

Database Driver & Version

No response

Description

Attaching Authorization middleware does not work for route groups using can() method, only via middleware('can...').

This does not work:

Route::prefix('{post}')
    ->can('access', 'post') // Middleware not registered.
    ->group(static function (): void {
        Route::get('/', 'show')
        ...
    });

Working example:

Route::prefix('{post}')
    ->middleware('can:access,post') // Middleware registered fine.
    ->group(static function (): void {
        Route::get('/', 'show')
        ...
    });

Steps To Reproduce

Route::prefix('{post}')
    ->can('access', 'post') // Middleware not registered.
    ->group(static function (): void {
        Route::get('/', 'show')
        ...
    });

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions