eaeedf2029
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
48 lines
1.3 KiB
PHP
48 lines
1.3 KiB
PHP
<?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,
|
|
]);
|
|
}
|
|
}
|