From 48d01190be7d4614f892928db0c80c8a1ce631f3 Mon Sep 17 00:00:00 2001 From: Bayu Hendra Winata Date: Sat, 23 Nov 2019 14:52:58 +0700 Subject: [PATCH] menu: allow multiple permission --- src/Menu.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Menu.php b/src/Menu.php index f7d8882..e283efe 100644 --- a/src/Menu.php +++ b/src/Menu.php @@ -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')); } }