diff --git a/CHANGELOG.md b/CHANGELOG.md index df820c6..cfc6cfe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). * Moved SVG icons into anonymous components for easier reuse / overwriting.[PR#35](https://github.com/mikebarlow/megaphone/pull/35) * Reworked notification type templates into components. [PR#35](https://github.com/mikebarlow/megaphone/pull/35) +* Added "mark all as read" feature for unread notifications. [PR#37](https://github.com/mikebarlow/megaphone/pull/37) ## [2.0.0] - 2023-09-11 diff --git a/resources/views/popout.blade.php b/resources/views/popout.blade.php index 64ed312..1d4ede8 100644 --- a/resources/views/popout.blade.php +++ b/resources/views/popout.blade.php @@ -11,11 +11,11 @@ @if ($unread->count() > 0)
-

+

Unread Notifications

-
diff --git a/src/Livewire/Megaphone.php b/src/Livewire/Megaphone.php index 2fcd79b..28c16a9 100644 --- a/src/Livewire/Megaphone.php +++ b/src/Livewire/Megaphone.php @@ -59,4 +59,15 @@ public function markAsRead(DatabaseNotification $notification) $notification->markAsRead(); $this->loadAnnouncements($this->getNotifiable()); } + + public function markAllRead() + { + DatabaseNotification::query() + ->where('notifiable_type', config('megaphone.model')) + ->where('notifiable_id', $this->notifiableId) + ->whereNull('read_at') + ->update(['read_at' => now()]); + + $this->loadAnnouncements($this->getNotifiable()); + } }