From 0d3f34ae8f67c0f0342f62aa4985f25ec8053fdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Duli=C3=A7i?= Date: Wed, 24 Feb 2021 19:14:18 +0300 Subject: [PATCH] check permission before showing notifications --- app/Http/ViewComposers/Header.php | 26 +++-- .../views/partials/admin/navbar.blade.php | 106 +++++++++--------- 2 files changed, 70 insertions(+), 62 deletions(-) diff --git a/app/Http/ViewComposers/Header.php b/app/Http/ViewComposers/Header.php index 6f523707c..5c19e1bd6 100644 --- a/app/Http/ViewComposers/Header.php +++ b/app/Http/ViewComposers/Header.php @@ -35,20 +35,22 @@ class Header ]; } - $unreads = $user->unreadNotifications; + if ($user->can('read-common-notifications')) { + $unreads = $user->unreadNotifications; - foreach ($unreads as $unread) { - $data = $unread->getAttribute('data'); + foreach ($unreads as $unread) { + $data = $unread->getAttribute('data'); - switch ($unread->getAttribute('type')) { - case 'App\Notifications\Purchase\Bill': - $bills[$data['bill_id']] = $data['amount']; - $notifications++; - break; - case 'App\Notifications\Sale\Invoice': - $invoices[$data['invoice_id']] = $data['amount']; - $notifications++; - break; + switch ($unread->getAttribute('type')) { + case 'App\Notifications\Purchase\Bill': + $bills[$data['bill_id']] = $data['amount']; + $notifications++; + break; + case 'App\Notifications\Sale\Invoice': + $invoices[$data['invoice_id']] = $data['amount']; + $notifications++; + break; + } } } diff --git a/resources/views/partials/admin/navbar.blade.php b/resources/views/partials/admin/navbar.blade.php index 64a982f77..f84c96925 100644 --- a/resources/views/partials/admin/navbar.blade.php +++ b/resources/views/partials/admin/navbar.blade.php @@ -141,62 +141,68 @@ @stack('navbar_notifications') - + + @endcan @stack('navbar_updates')