feat: header con mensajes y notificaciones en tiempo real

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-26 14:14:46 -06:00
parent 9dd5ac6cbf
commit eaeedf2029
8 changed files with 298 additions and 149 deletions
+47
View File
@@ -0,0 +1,47 @@
<?php
namespace App\View\Composers;
use App\Models\Message;
use Illuminate\View\View;
class HeaderComposer
{
public function compose(View $view): void
{
if (!auth()->check()) {
return;
}
$userId = auth()->id();
// Últimas conversaciones con mensajes no leídos
$unreadConversations = Message::where('receiver_id', $userId)
->whereNull('read_at')
->with('sender')
->orderBy('created_at', 'desc')
->get()
->unique('user_id')
->take(5);
$unreadMessagesCount = Message::where('receiver_id', $userId)
->whereNull('read_at')
->count();
// Notificaciones no leídas
$unreadNotifications = auth()->user()
->unreadNotifications()
->latest()
->take(5)
->get();
$unreadNotificationsCount = auth()->user()->unreadNotifications()->count();
$view->with([
'headerUnreadConversations' => $unreadConversations,
'headerUnreadMessagesCount' => $unreadMessagesCount,
'headerUnreadNotifications' => $unreadNotifications,
'headerUnreadNotificationsCount' => $unreadNotificationsCount,
]);
}
}