public function submitFiles()
 {
     $files = Input::get('data');
     $objectValidities = $objectManagers = $queuedObjects = [];
     $doesNotContainErrors = true;
     // Find each object from file
     for ($i = 0; $i < count($files); $i++) {
         $objectManagers[$i] = App::make('SpaceXStats\\ModelManagers\\Objects\\ObjectFromFile');
         $objectValidities[$i] = $objectManagers[$i]->isValid($files[$i]) ? true : $objectManagers[$i]->getErrors();
         if ($objectValidities[$i] !== true) {
             $doesNotContainErrors = false;
         }
     }
     // Check if there are errors, if no, add all to db, if yes, return with errors.
     if ($doesNotContainErrors) {
         // add all objects to db
         for ($i = 0; $i < count($files); $i++) {
             $queuedObjects[$i] = $objectManagers[$i]->create();
         }
         // nothing bad happened, let's also create an optional collection if asked to
         if (Input::get('collection') != null) {
             $collection = Collection::create(['creating_user_id' => Auth::id(), 'title' => Input::get('collection.title'), 'summary' => Input::get('collection.summary')]);
             // and associate it with the given files
             $collection->objects()->saveMany($queuedObjects);
         }
     } else {
         return response()->json($objectValidities, 400);
     }
     // redirect to mission control
     Session::flash('flashMessage', 'Done!');
     return response()->json(null, 204);
 }
 public function create()
 {
     if ($this->collection->isValid(Input::all())) {
         $collection = Collection::create(array('creating_user_id' => Auth::id(), 'title' => Input::get('title'), 'summary' => Input::get('summary')));
         return response()->json($collection);
     }
     return response()->json(null, 400);
 }