public function run() { // COTS1 Spacecraft::create(['name' => 'Dragon C1', 'type' => 'Dragon 1']); // COTS2+ Spacecraft::create(['name' => 'Dragon C2', 'type' => 'Dragon 1']); // CRS-1 Spacecraft::create(['name' => 'Dragon C3', 'type' => 'Dragon 1']); Spacecraft::create(['name' => 'Dragon C4', 'type' => 'Dragon 1']); // CRS-3 Spacecraft::create(['name' => 'Dragon C5', 'type' => 'Dragon 1.1']); Spacecraft::create(['name' => 'Dragon C7', 'type' => 'Dragon 1.1']); Spacecraft::create(['name' => 'Dragon C8', 'type' => 'Dragon 1.1']); Spacecraft::create(['name' => 'Dragon C9', 'type' => 'Dragon 1.1']); Spacecraft::create(['name' => 'Dragon C10', 'type' => 'Dragon 1.1']); }
private function manageSpacecraftFlightRelation() { $currentSpacecraftFlight = $this->mission->spacecraftFlight; $spacecraftInput = array_pull($this->input['mission']['spacecraft_flight'], 'spacecraft'); // If the spacecraft flight input exists (create/update) if (!is_null($this->input['mission']['spacecraft_flight'])) { $spacecraftFlight = $currentSpacecraftFlight->count() == true ? $this->mission->spacecraftFlight->fill($spacecraftInput) : new SpacecraftFlight($spacecraftInput); // Create spacecraft if it is not being reused or otherwise find it and update it $spacecraft = array_key_exists('spacecraft_id', $spacecraftInput) ? Spacecraft::find($spacecraftInput['spacecraft_id']) : new Spacecraft(); $spacecraft->fill($spacecraftInput); $spacecraft->spacecraftFlights()->save($spacecraftFlight); $spacecraftFlight->mission()->associate($this->mission); // Now manage astronautFlights and astronauts $this->manageAstronautFlightsRelation(); // If the input spacecraft flight does not exist and the current spacecraft flight does (delete) } elseif (is_null($this->input['mission']['spacecraft_flight']) && !is_null($currentSpacecraftFlight)) { $this->mission->spacecraftFlight->delete(); // Also delete any astronaut flights & spacecraft (Maybe manage with database cascading?) } }
public function getCreate() { JavaScript::put(['destinations' => Destination::all(['destination_id', 'destination'])->toArray(), 'missionTypes' => MissionType::all(['name', 'mission_type_id'])->toArray(), 'launchSites' => Location::where('type', 'Launch Site')->get()->toArray(), 'landingSites' => Location::where('type', 'Landing Site')->orWhere('type', 'ASDS')->get()->toArray(), 'vehicles' => Vehicle::all(['vehicle', 'vehicle_id'])->toArray(), 'parts' => Part::whereDoesntHave('partFlights', function ($q) { $q->where('landed', false); })->get()->toArray(), 'spacecraft' => Spacecraft::all()->toArray(), 'astronauts' => Astronaut::all()->toArray()]); return view('missions.create'); }