Skip to content

Commit c0b441d

Browse files
committed
Added a feature to be able to check
multiple permissions by passing array of permission slugs
1 parent 4b97721 commit c0b441d

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/Helpers/Helpers.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,37 @@ function checkPermission(string $permission) : bool
196196
return true;
197197
}
198198
return false;
199+
}
200+
201+
function checkPermissions(array $permissions) : bool
202+
{
203+
if(auth()->check())
204+
{
205+
$auth = auth()->user();
206+
$user_roles = \Obrainwave\AccessTree\Models\UserRole::where('user_id', $auth->id)->get();
207+
208+
if(isRootUser($auth->id))
209+
{
210+
return true;
211+
}
212+
213+
}else{
214+
return false;
215+
}
216+
217+
$role_permissions = [];
218+
foreach($user_roles as $role)
219+
{
220+
$rolePermissions = \Obrainwave\AccessTree\Models\RoleHasPermission::where('role_id', $role->role_id)->get();
221+
222+
foreach($rolePermissions as $rolePermission)
223+
{
224+
$role_permissions[] = $rolePermission->permission->slug;
225+
}
226+
}
227+
if(array_intersect($permissions, $role_permissions))
228+
{
229+
return true;
230+
}
231+
return false;
199232
}

0 commit comments

Comments
 (0)