/** * Return the view achievements with all the users games informations */ public function achievements() { $user = User::find(Auth::id()); $users = DB::table('users')->orderBy('points', 'desc')->get(); $i = 0; $row = 0; $length = sizeof($users); while ($row == 0 && $i < $length) { if ($users[$i]->id == $user->id) { $row = $i + 1; } $i++; } $topranking = DB::table('users')->orderBy('points', 'desc')->where('points', '>', $user->points)->take(2)->get(); $lowranking = DB::table('users')->orderBy('points', 'desc')->where('points', '<', $user->points)->take(2)->get(); $games = GameHistory::with('game')->orderBy('created_at', 'desc')->where('user_id', '=', $user->id)->take(5)->get(); $badges = Auth::user()->achievements()->get(); return view('profile/achievements', compact('user', 'topranking', 'lowranking', 'games', 'badges', 'row')); }