composer('*', function ($view): void { $user = auth()->user(); if (!$user) { $view->with('layoutUnreadNotificationsCount', 0); $view->with('layoutRecentNotifications', collect()); return; } $recentNotifications = UserNotification::query() ->where('user_id', (int) $user->id) ->latest('id') ->take(5) ->get(); $view->with('layoutUnreadNotificationsCount', $recentNotifications->whereNull('read_at')->count()); $view->with('layoutRecentNotifications', $recentNotifications); }); } }