2026-06-16 18:05:53 +02:00
|
|
|
<?php
|
|
|
|
|
|
2026-06-19 16:54:09 +02:00
|
|
|
namespace App\Livewire\Common;
|
2026-06-16 18:05:53 +02:00
|
|
|
|
|
|
|
|
use Livewire\Component;
|
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
|
|
|
|
|
|
class NotificationBell extends Component
|
|
|
|
|
{
|
|
|
|
|
public $notifications = [];
|
|
|
|
|
public $unreadCount = 0;
|
|
|
|
|
public $showDropdown = false;
|
|
|
|
|
|
|
|
|
|
public function mount()
|
|
|
|
|
{
|
|
|
|
|
$this->loadNotifications();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function loadNotifications()
|
|
|
|
|
{
|
|
|
|
|
$user = Auth::user();
|
|
|
|
|
$this->notifications = $user->notifications()->latest()->take(10)->get()->toArray();
|
|
|
|
|
$this->unreadCount = $user->unreadNotifications()->count();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function markAsRead($id)
|
|
|
|
|
{
|
|
|
|
|
Auth::user()->notifications()->where('id', $id)->update(['read_at' => now()]);
|
|
|
|
|
$this->loadNotifications();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function markAllAsRead()
|
|
|
|
|
{
|
|
|
|
|
Auth::user()->unreadNotifications->markAsRead();
|
|
|
|
|
$this->loadNotifications();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function render()
|
|
|
|
|
{
|
2026-06-19 16:54:09 +02:00
|
|
|
return view('livewire.common.notification-bell');
|
2026-06-16 18:05:53 +02:00
|
|
|
}
|
|
|
|
|
}
|