Skip to content

Commit fba839a

Browse files
authored
Prevent duplicate query in notifications component (#493)
* Prevent duplicate query * Apply fixes from StyleCI
1 parent ed1f453 commit fba839a

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

app/Http/Livewire/Notifications.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace App\Http\Livewire;
44

55
use App\Policies\NotificationPolicy;
6-
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
76
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
87
use Illuminate\Notifications\DatabaseNotification;
98
use Illuminate\Support\Facades\Auth;
@@ -34,18 +33,14 @@ public function getNotificationProperty(): DatabaseNotification
3433
return DatabaseNotification::findOrFail($this->notificationId);
3534
}
3635

37-
public function markAsRead(string $notificationId): LengthAwarePaginator
36+
public function markAsRead(string $notificationId): void
3837
{
3938
$this->notificationId = $notificationId;
4039

4140
$this->authorize(NotificationPolicy::MARK_AS_READ, $this->notification);
4241

4342
$this->notification->markAsRead();
4443

45-
$unreadNotifications = Auth::user()->unreadNotifications()->paginate(10);
46-
47-
$this->emit('NotificationMarkedAsRead', $unreadNotifications->total());
48-
49-
return $unreadNotifications;
44+
$this->emit('NotificationMarkedAsRead', Auth::user()->unreadNotifications()->count());
5045
}
5146
}

0 commit comments

Comments
 (0)