42 lines
850 B
PHP
42 lines
850 B
PHP
<?php
|
|
|
|
namespace App\Livewire;
|
|
|
|
use App\Models\Notification;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Livewire\Attributes\Computed;
|
|
use Livewire\Component;
|
|
|
|
class NotificationBell extends Component
|
|
{
|
|
public function markAsRead(int $id): void
|
|
{
|
|
Notification::findOrFail($id)->markAsRead();
|
|
}
|
|
|
|
public function markAllAsRead(): void
|
|
{
|
|
Notification::markAllAsRead();
|
|
}
|
|
|
|
#[Computed]
|
|
public function unreadCount(): int
|
|
{
|
|
return Notification::unread()->count();
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, Notification>
|
|
*/
|
|
#[Computed]
|
|
public function notifications(): Collection
|
|
{
|
|
return Notification::recent()->get();
|
|
}
|
|
|
|
public function render(): View
|
|
{
|
|
return view('livewire.notification-bell');
|
|
}
|
|
}
|