public function index(\App\Gameweek $gameweek = null, \App\Month $month = null)
 {
     $user = null;
     $users = \App\User::ranked()->orderBy('rank')->get();
     $lastFixture = \App\Fixture::over()->orderBy('kickoff', 'desc')->first();
     $activeTabs = ['active', '', ''];
     if (!$month or !$month->hasStarted()) {
         $month = $lastFixture->gameweek->month;
     } else {
         $activeTabs = ['', 'active', ''];
     }
     if (!$gameweek or !$gameweek->hasCompletedFixture()) {
         $gameweek = $lastFixture->gameweek;
     } else {
         $activeTabs = ['', '', 'active'];
     }
     if (\Auth::check()) {
         $user = \Auth::user();
     }
     $months = \App\Month::orderBy('id', 'desc')->get()->filter(function ($month) {
         return $month->hasStarted();
     });
     $gameweeks = \App\Gameweek::orderBy('id', 'desc')->get()->filter(function ($gw) {
         return $gw->hasCompletedFixture();
     });
     $gameweekUsers = $gameweek->predictors()->orderBy('gameweek_user.rank', 'asc')->get();
     $monthUsers = $month->users()->orderBy('month_user.rank', 'asc')->get();
     $nameOfPage = 'standings';
     return view('pages.standings', compact('gameweeks', 'months', 'users', 'gameweekUsers', 'monthUsers', 'month', 'gameweek', 'user', 'activeTabs', 'nameOfPage'));
 }
Пример #2
0
 public function show(\App\User $user, \App\Gameweek $gameweekInFocus = null)
 {
     //Get the last "over" fixture
     $lastFixture = \App\Fixture::over()->orderBy('kickoff', 'desc')->first();
     if (!$gameweekInFocus or !$gameweekInFocus->hasCompletedFixture()) {
         //Get the corresponding gameweek and eager load its fixtures
         $gameweekInFocus = $lastFixture->gameweek()->with(['fixtures' => function ($query) {
             $query->over();
         }])->first();
     } else {
         $gameweekInFocus->load(['fixtures' => function ($query) {
             $query->over();
         }]);
     }
     $gameweeks = \App\Gameweek::orderBy('id', 'desc')->get()->filter(function ($gw) {
         return $gw->hasCompletedFixture();
     });
     $badges = $user->badges()->orderBy('badge_user.gameweek_id', 'asc')->get();
     return view('users.show', compact('user', 'gameweekInFocus', 'gameweeks', 'lastFixture', 'badges'));
 }