/**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @param  String $model
  * @return mixed
  */
 public function handle($request, Closure $next, $model)
 {
     if ($model == 'Mission') {
         Mission::whereSlug(Route::input('slug'))->firstOrFail();
     } elseif ($model == 'Object') {
         Object::findOrFail(Route::input('object_id'));
     } elseif ($model == 'Tag') {
         Tag::where('name', Route::input('slug'))->firstOrFail();
     }
     return $next($request);
 }
 public function mission($slug)
 {
     return view('missionControl.collections.mission', ['collection' => Mission::whereSlug($slug)->with('objects')->first()]);
 }
 /**
  * GET, /missions/{slug}/raw. Get raw mission data, used for a raw data download on a mission page.
  *
  * @param $slug
  * @return \Illuminate\Http\Response
  */
 public function raw($slug)
 {
     $mission = Mission::whereSlug($slug)->first();
     $json = ['json_generated_at' => \Carbon\Carbon::now()->toDateTimeString(), 'mission_type' => $mission->missionType->name, 'launch_date_time' => $mission->launch_date_time, 'name' => $mission->name, 'contractor' => $mission->contractor, 'vehicle' => $mission->vehicle->vehicle, 'destination' => $mission->destination->destination, 'launch_site' => $mission->launchSite->fullLocation, 'summary' => $mission->summary, 'status' => $mission->status, 'outcome' => $mission->outcome, 'fairings_recovered' => $mission->fairings_recovered, 'mission_created_at' => $mission->created_at->toDateTimeString()];
     return response()->json($json, 200, array('Content-type' => 'application/json', 'Content-Disposition' => 'attachment;filename="' . $slug . '.json"'));
 }
 public function get($slug)
 {
     // get a mission in the future if a launch is exact
     $missions = Mission::whereSlug($slug)->whereUpcoming()->whereNotNull('launch_exact')->with('launchSite')->get();
     return $this->returnCalendarOrRedirect($missions, $slug);
 }