Skip to content
This repository has been archived by the owner on Feb 15, 2023. It is now read-only.

Commit

Permalink
menu: allow multiple permission
Browse files Browse the repository at this point in the history
  • Loading branch information
uyab committed Nov 23, 2019
1 parent f280fa4 commit 48d0119
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,24 @@ public function all()

protected function filterByVisibility(Item $item)
{
$permission = $item->data('permission');

// If menu doesn't define permission, we assume this menu visible to everyone
// Otherwise, check if current user has access
return $item->data('permission') === null || auth()->user()->can($item->data('permission'));
if ($permission === null) {
return true;
}

// If it was multiple permissions, we check using OR conditions.
// It means, user only need to have one of the permissions
if (is_array($permission)) {
foreach ($permission as $perm) {
if (auth()->user()->can($perm)) {
return true;
}
}
}

return auth()->user()->can($item->data('permission'));
}
}

0 comments on commit 48d0119

Please sign in to comment.