feat: header con mensajes y notificaciones en tiempo real
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user