@@ -32,19 +32,23 @@ public function resource(Resource $resource)
3232
3333 protected function buildGatesForModel (Model $ model , Resource $ resource , array $ gates )
3434 {
35- $ authorizedToView = $ resource ->authorizedTo ('view ' , $ model );
36- $ authorizedToUpdate = $ resource ->authorizedTo ('update ' , $ model );
37- $ authorizedToDelete = $ resource ->authorizedTo ('delete ' , $ model );
38- $ authorizedToRestore = $ resource ->authorizedTo ('restore ' , $ model );
39- $ authorizedToForceDelete = $ resource ->authorizedTo ('forceDelete ' , $ model );
35+ $ nameMap = [
36+ 'view ' => config ('rest.gates.names.authorized_to_view ' ),
37+ 'update ' => config ('rest.gates.names.authorized_to_update ' ),
38+ 'delete ' => config ('rest.gates.names.authorized_to_delete ' ),
39+ 'restore ' => config ('rest.gates.names.authorized_to_restore ' ),
40+ 'forceDelete ' => config ('rest.gates.names.authorized_to_force_delete ' ),
41+ ];
4042
41- return array_merge (
42- in_array ('view ' , $ gates ) ? [config ('rest.gates.names.authorized_to_view ' ) => $ authorizedToView ->message () ?? $ authorizedToView ->allowed ()] : [],
43- in_array ('update ' , $ gates ) ? [config ('rest.gates.names.authorized_to_update ' ) => $ authorizedToUpdate ->message () ?? $ authorizedToUpdate ->allowed ()] : [],
44- in_array ('delete ' , $ gates ) ? [config ('rest.gates.names.authorized_to_delete ' ) => $ authorizedToDelete ->message () ?? $ authorizedToDelete ->allowed ()] : [],
45- in_array ('restore ' , $ gates ) ? [config ('rest.gates.names.authorized_to_restore ' ) => $ authorizedToRestore ->message () ?? $ authorizedToRestore ->allowed ()] : [],
46- in_array ('forceDelete ' , $ gates ) ? [config ('rest.gates.names.authorized_to_force_delete ' ) => $ authorizedToForceDelete ->message () ?? $ authorizedToForceDelete ->allowed ()] : [],
47- );
43+ $ result = [];
44+ foreach ($ gates as $ gate ) {
45+ if (isset ($ nameMap [$ gate ])) {
46+ $ auth = $ resource ->authorizedTo ($ gate , $ model );
47+ $ result [$ nameMap [$ gate ]] = $ auth ->message () ?? $ auth ->allowed ();
48+ }
49+ }
50+
51+ return $ result ;
4852 }
4953
5054 /**
0 commit comments