load([ 'friends.friend:id,username,look', 'guilds.guild:id,name,badge', 'profileGuestbook.user:id,username,look', 'photos', 'badges', ]); $showStats = (bool) (WebsiteSetting::where('key', 'profile_show_stats')->first()?->value ?? '1'); $showOnline = (bool) (WebsiteSetting::where('key', 'profile_show_online_status')->first()?->value ?? '1'); 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' => $this->getAccountAge($user->account_created), 'lastLogin' => $this->getLastLogin($user->last_login), 'totalFriends' => $user->friends()->count(), 'totalGuilds' => $user->guilds()->count(), ]); } private function getAccountAge(int $timestamp): string { $created = Carbon::createFromTimestamp($timestamp); if ($created->diffInYears() >= 1) { return $created->diffInYears() . ' ' . str('year')->plural($created->diffInYears()); } if ($created->diffInMonths() >= 1) { return $created->diffInMonths() . ' ' . str('month')->plural($created->diffInMonths()); } if ($created->diffInWeeks() >= 1) { return $created->diffInWeeks() . ' ' . str('week')->plural($created->diffInWeeks()); } return $created->diffInDays() . ' ' . str('day')->plural($created->diffInDays()); } private function getLastLogin(int $timestamp): string { $lastLogin = Carbon::createFromTimestamp($timestamp); $diffInMinutes = $lastLogin->diffInMinutes(); if ($diffInMinutes < 1) { return 'Just now'; } if ($diffInMinutes < 60) { return $lastLogin->diffForHumans(); } if ($diffInMinutes < 10080) { return $lastLogin->diffForHumans(); } return $lastLogin->format('d M Y'); } }