where('user_id', $userId)->count(); } catch (\Throwable $e) { $uploadCount = 0; } try { // legacy table name fallback handled elsewhere; here we look for user_favorites or favourites $favCount = DB::table('user_favorites')->where('user_id', $userId)->count(); } catch (\Throwable $e) { try { $favCount = DB::table('favourites')->where('user_id', $userId)->count(); } catch (\Throwable $e) { $favCount = 0; } } try { $msgCount = DB::table('messages')->where('reciever_id', $userId)->whereNull('read_at')->count(); } catch (\Throwable $e) { $msgCount = 0; } try { $noticeCount = DB::table('notification')->where('user_id', $userId)->where('new', 1)->count(); } catch (\Throwable $e) { $noticeCount = 0; } try { $profile = DB::table('user_profiles')->where('user_id', $userId)->first(); $avatar = $profile->avatar ?? null; } catch (\Throwable $e) { $avatar = null; } $displayName = Auth::user()->name ?: (Auth::user()->username ?? ''); } $view->with(compact('userId','uploadCount', 'favCount', 'msgCount', 'noticeCount', 'avatar', 'displayName')); }); } }