Skip to content

Commit

Permalink
Added method to component to mark unread notifications as read.
Browse files Browse the repository at this point in the history
Updated the changelog
  • Loading branch information
mikebarlow committed Sep 3, 2024
1 parent f03dc32 commit 2101f62
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions resources/views/popout.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

@if ($unread->count() > 0)
<div class="border-b pb-2 border-gray-300 text-gray-600 flex justify-between">
<h2 tabindex="0" class="focus:outline-none text-sm leading-normal pt-8">
<h2 class="focus:outline-none text-sm leading-normal pt-8">
Unread Notifications
</h2>

<button tabindex="0" class="focus:outline-none text-sm leading-normal pt-8 hover:text-indigo-700">
<button class="focus:outline-none text-sm leading-normal pt-8 hover:text-indigo-700" wire:click="markAllRead()">
Mark all as read
</button>
</div>
Expand Down
11 changes: 11 additions & 0 deletions src/Livewire/Megaphone.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 2101f62

Please sign in to comment.