/**
  * GET (HTTP). Home.
  *
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
  */
 public function home()
 {
     if (Auth::isSubscriber()) {
         // Fetch data
         $objects['latest'] = Object::authedVisibility()->inMissionControl()->orderBy('created_at', 'desc')->take(10)->get();
         $objects['hot'] = Object::authedVisibility()->inMissionControl()->selectRaw('objects.*, LOG10(greatest(1, count(comments.object_id)) + greatest(1, count(favorites.object_id))) / TIMESTAMPDIFF(HOUR, objects.actioned_at, NOW()) as score')->leftJoin('comments', 'comments.object_id', '=', 'objects.object_id')->leftJoin('favorites', 'favorites.object_id', '=', 'objects.object_id')->groupBy('objects.object_id')->orderBy(DB::raw('score'))->take(10)->get();
         $objects['discussions'] = Object::authedVisibility()->inMissionControl()->where('type', MissionControlType::Text)->join('comments', 'comments.object_id', '=', 'objects.object_id')->orderBy('comments.created_at')->select('objects.*')->take(10)->get();
         $objects['mission'] = Object::authedVisibility()->inMissionControl()->whereHas('Mission', function ($q) {
             $q->future()->take(1);
         })->take(10)->get();
         $objects['random'] = Object::authedVisibility()->inMissionControl()->orderByRaw("RAND()")->take(10)->get();
         // Leaderboards
         $leaderboards['week'] = User::join('awards', 'awards.user_id', '=', 'users.user_id')->selectRaw('users.user_id, users.username, sum(awards.value) as totalDeltaV')->where('awards.created_at', '>=', Carbon::now()->subWeek())->groupBy('users.user_id')->take(10)->get();
         $leaderboards['month'] = User::join('awards', 'awards.user_id', '=', 'users.user_id')->selectRaw('users.user_id, users.username, sum(awards.value) as totalDeltaV')->where('awards.created_at', '>=', Carbon::now()->subMonth())->groupBy('users.user_id')->take(10)->get();
         $leaderboards['year'] = User::join('awards', 'awards.user_id', '=', 'users.user_id')->selectRaw('users.user_id, users.username, sum(awards.value) as totalDeltaV')->where('awards.created_at', '>=', Carbon::now()->subYear())->groupBy('users.user_id')->take(10)->get();
         $leaderboards['alltime'] = User::join('awards', 'awards.user_id', '=', 'users.user_id')->selectRaw('users.user_id, users.username, sum(awards.value) as totalDeltaV')->groupBy('users.user_id')->take(10)->get();
         // Comments
         $comments = Comment::with(['object' => function ($query) {
             $query->select('object_id', 'title');
         }])->with(['user' => function ($query) {
             $query->select('user_id', 'username');
         }])->orderBy('created_at', 'DESC')->take(10)->get();
         // Favorites
         $favorites = Favorite::with(['object' => function ($query) {
             $query->select('object_id', 'title');
         }])->with(['user' => function ($query) {
             $query->select('user_id', 'username');
         }])->orderBy('created_at', 'DESC')->take(10)->get();
         // Downloads
         $downloads = Download::with(['object' => function ($query) {
             $query->select('object_id', 'title');
         }])->with(['user' => function ($query) {
             $query->select('user_id', 'username');
         }])->orderBy('created_at', 'DESC')->take(10)->get();
         return view('missionControl.home', ['upcomingMission' => Mission::future()->first(), 'leaderboards' => $leaderboards, 'objects' => $objects, 'comments' => $comments, 'favorites' => $favorites, 'downloads' => $downloads]);
     } else {
         return redirect()->action('MissionControl\\MissionControlController@about');
     }
 }
 public function favorite($object_id)
 {
     if (Auth::isSubscriber()) {
         // Create Favorite
         if (request()->isMethod('post')) {
             if (Auth::user()->favorites()->count() == 0) {
                 Favorite::create(array('object_id' => $object_id, 'user_id' => Auth::id()));
             }
             // Delete Favorite
         } elseif (request()->isMethod('delete')) {
             Auth::user()->favorites()->where('object_id', $object_id)->firstOrFail()->delete();
         }
         Redis::sadd('objects:toReindex', $object_id);
         return response()->json(null, 204);
     }
     return response()->json(false, 401);
 }