Skip to content

Commit

Permalink
Auto-discover nested policies following conventional, parallel hierar…
Browse files Browse the repository at this point in the history
…chy (#54493)

* Remove redundant check

* Support parallel conventional hierachies

* formatting

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
jasonmccreary and taylorotwell authored Feb 6, 2025
1 parent e7f317b commit 4646699
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Access/Gate.php
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,9 @@ protected function guessPolicyName($class)
$classDirname = implode('\\', array_slice($classDirnameSegments, 0, $index));

return $classDirname.'\\Policies\\'.class_basename($class).'Policy';
})->when(str_contains($classDirname, '\\Models\\'), function ($collection) use ($class, $classDirname) {
return $collection->concat([str_replace('\\Models\\', '\\Policies\\', $classDirname).'\\'.class_basename($class).'Policy'])
->concat([str_replace('\\Models\\', '\\Models\\Policies\\', $classDirname).'\\'.class_basename($class).'Policy']);
})->reverse()->values()->first(function ($class) {
return class_exists($class);
}) ?: [$classDirname.'\\Policies\\'.class_basename($class).'Policy']);
Expand Down

0 comments on commit 4646699

Please sign in to comment.