- Install laravel/reverb + laravel-echo + pusher-js - Configure broadcasting to reverb in .env.example + .env - Add Echo + Pusher client in resources/js/app.js - Update all 14 notifications to implement ShouldBroadcast + broadcastOn() - Update NotificationBell component to listen for real-time events - Add Livewire.emit in notification-bell blade for JS-to-Livewire bridge Tests: 101 passing (319 assertions)
53 lines
1.2 KiB
PHP
53 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Common;
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Livewire\Attributes\On;
|
|
use Livewire\Component;
|
|
|
|
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();
|
|
}
|
|
|
|
#[On('notification-received')]
|
|
public function handleNotification($message = 'Nueva notificación')
|
|
{
|
|
$this->loadNotifications();
|
|
$this->dispatch('notify', $message);
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.common.notification-bell');
|
|
}
|
|
}
|