load([ 'friends.friend:id,username,look', 'guilds.guild:id,name,badge', 'profileGuestbook.user:id,username,look', 'photos', 'badges', ]); $showStats = WebsiteSetting::where('key', 'profile_show_stats')->first()?->value ?? '1'; $showOnline = WebsiteSetting::where('key', 'profile_show_online_status')->first()?->value ?? '1'; $accountAge = $this->getAccountAge($user->account_created); $lastLogin = $this->getLastLogin($user->last_login); $totalFriends = $user->friends()->count(); $totalGuilds = $user->guilds()->count(); return view('user.profile', [ 'user' => $user, 'friends' => $user->friends->take(10), 'groups' => $user->guilds->take(5), 'guestbook' => $user->profileGuestbook->take(5), 'photos' => $user->photos->take(3), 'badges' => $user->badges->take(3), 'showStats' => $showStats, 'showOnline' => $showOnline, 'accountAge' => $accountAge, 'lastLogin' => $lastLogin, 'totalFriends' => $totalFriends, 'totalGuilds' => $totalGuilds, ]); } private function getAccountAge(int $timestamp): string { $created = Carbon::createFromTimestamp($timestamp); $now = Carbon::now(); $days = $created->diffInDays($now); if ($days < 7) { return $days . ' day' . ($days !== 1 ? 's' : ''); } elseif ($days < 30) { $weeks = floor($days / 7); return $weeks . ' week' . ($weeks !== 1 ? 's' : ''); } elseif ($days < 365) { $months = floor($days / 30); return $months . ' month' . ($months !== 1 ? 's' : ''); } else { $years = floor($days / 365); return $years . ' year' . ($years !== 1 ? 's' : ''); } } private function getLastLogin(int $timestamp): string { $lastLogin = Carbon::createFromTimestamp($timestamp); $now = Carbon::now(); $diff = $now->diffInMinutes($lastLogin); if ($diff < 1) { return 'Just now'; } elseif ($diff < 60) { return $diff . ' minute' . ($diff !== 1 ? 's' : '') . ' ago'; } elseif ($diff < 1440) { $hours = floor($diff / 60); return $hours . ' hour' . ($hours !== 1 ? 's' : '') . ' ago'; } elseif ($diff < 10080) { $days = floor($diff / 1440); return $days . ' day' . ($days !== 1 ? 's' : '') . ' ago'; } else { return $lastLogin->format('d M Y'); } } }