Skip to content

Conversation

bonroyage
Copy link
Contributor

This fixes two issues with the can method on route groups. First, an exception if you defined can on multiple nested group levels. Second, that the models (second parameter) would not be inherited.

Exception with multiple nested group levels

  ErrorException 

  Array to string conversion

  at vendor/laravel/framework/src/Illuminate/Routing/Route.php:1103
    1099▕     {
    1100▕         $ability = enum_value($ability);
    1101▕ 
    1102▕         return empty($models)
  ➜ 1103▕             ? $this->middleware(['can:'.$ability])
    1104▕             : $this->middleware(['can:'.$ability.','.implode(',', Arr::wrap($models))]);
    1105▕     }
    1106▕ 
    1107▕     /**

Failing test result for testCanSetMiddlewareCanWithModelsOnGroups

Failed asserting that two strings are equal.
Expected :'can:view,post'
Actual   :'can:view'

Failing test result for testCanSetMiddlewareCanNestedOnGroups

Failed asserting that two arrays are equal.

Expected:
Array (
    0 => 'can:access-admin'
    1 => 'can:edit,post'
)

Actual:
Array (
    0 => 'can:Array'
)

@taylorotwell taylorotwell merged commit 309c087 into laravel:12.x Sep 25, 2025
65 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants