@@ -61,9 +61,12 @@ protected function perimeters(): array
6161 */
6262 public function applies (Model $ user , string $ method , Model $ model ): bool
6363 {
64+ // If the method is viewAny, we check instead if he has any 'view' right on different perimeters
65+ $ appliesMethod = config (sprintf ('access-control.methods.%s ' , $ method )) ?? $ method ;
66+
6467 foreach ($ this ->perimeters () as $ perimeter ) {
65- if ($ perimeter ->applyAllowedCallback ($ user , $ method )) {
66- // If the model doesn't exists , it means the method is not related to a model
68+ if ($ perimeter ->applyAllowedCallback ($ user , $ appliesMethod )) {
69+ // If the model doesn't exist , it means the method is not related to a model
6770 // so we don't need to activate the should result since we can't compare an existing model
6871 if (!$ model ->exists ) {
6972 return true ;
@@ -131,7 +134,7 @@ protected function applyQueryControl(Builder $query, Model $user): Builder
131134 };
132135
133136 foreach ($ this ->perimeters () as $ perimeter ) {
134- if ($ perimeter ->applyAllowedCallback ($ user , ' view ' )) {
137+ if ($ perimeter ->applyAllowedCallback ($ user , config ( ' access-control.methods. view ') )) {
135138 if (config ('access-control.queries.isolate_perimeter_queries ' )) {
136139 $ query = $ query ->orWhere (function (Builder $ query ) use ($ user , $ perimeter ) {
137140 $ perimeter ->applyQueryCallback ($ query , $ user );
@@ -166,7 +169,7 @@ protected function applyScoutQueryControl(\Laravel\Scout\Builder $query, Model $
166169 };
167170
168171 foreach ($ this ->perimeters () as $ perimeter ) {
169- if ($ perimeter ->applyAllowedCallback ($ user , ' view ' )) {
172+ if ($ perimeter ->applyAllowedCallback ($ user , config ( ' access-control.methods. view ') )) {
170173 $ query = $ perimeter ->applyScoutQueryCallback ($ query , $ user );
171174
172175 $ noResultCallback = function ($ query ) {return $ query ; };
0 commit comments