public function index()
 {
     $usersData = [];
     $usersData['count'] = User::all()->count();
     $usersData['incompleteCount'] = User::where('status', 0)->count();
     $picsData = [];
     $picsData['count'] = Pic::all()->count();
     $clubsData = [];
     $clubsData['count'] = Club::all()->count();
     $badgesData = [];
     $badgesData['count'] = Badge::all()->count();
     $fixtures = Fixture::all();
     $fixturesData = [];
     $fixturesData['count'] = $fixtures->count();
     $fixturesData['overCount'] = $fixtures->filter(function ($fxt) {
         return $fxt->isOver();
     })->count();
     $fixturesData['closedNotOverCount'] = $fixtures->filter(function ($fxt) {
         return $fxt->isClosed() and !$fxt->isOver();
     })->count();
     $gameweeks = Gameweek::all();
     $gameweeksData = [];
     $gameweeksData['count'] = $gameweeks->count();
     $gameweeksData['completeCount'] = Gameweek::complete()->get()->count();
     $gameweeksData['pendingCount'] = Gameweek::incomplete()->get()->filter(function ($gw) {
         return $gw->hasCompletedFixture();
     })->count();
     $adminsData = [];
     $adminsData['count'] = Admin::all()->count();
     return view('admin.dashboard.index', compact('usersData', 'picsData', 'clubsData', 'badgesData', 'fixturesData', 'gameweeksData', 'adminsData'));
 }
 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'));
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     parent::boot($router);
     $router->bind('username', function ($username) {
         return \App\User::where('username', $username)->firstOrFail();
     });
     $router->bind('gwid', function ($gwid) {
         return \App\Gameweek::where('id', $gwid)->firstOrFail();
     });
     $router->bind('monthid', function ($monthid) {
         return \App\Month::where('id', $monthid)->firstOrFail();
     });
 }
 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'));
 }
 /**
  * Show the application home (predict) page to the user
  * 
  * @return Response
  */
 public function index()
 {
     $user = \Auth::user();
     $gws = \App\Gameweek::incomplete()->take(2)->with('fixtures')->with(['fixtures.predictions' => function ($query) use($user) {
         $query->where('user_id', $user->id);
     }])->get();
     foreach ($gws as $gw) {
         $userGameweek = $user->gameweeks()->where('gameweek_id', $gw->id)->first();
         $boostId = null;
         $boostedClosed = false;
         if ($userGameweek) {
             $boostId = $userGameweek->pivot->boost_id;
             if ($boostId) {
                 $boostedClosed = \App\Fixture::find($boostId)->isClosed();
             }
         }
         $gw->boostId = $boostId;
         $gw->boostedClosed = $boostedClosed;
     }
     $nameOfPage = 'home';
     return view('pages.home', compact('gws', 'user', 'nameOfPage'));
 }
 public function complete($id)
 {
     $gameweek = Gameweek::find($id);
     $this->performComputations($gameweek);
     $gameweek->complete = true;
     $gameweek->save();
     return redirect('/admin/gameweek');
 }