$type, ], ['name' => $type]); return $subfleet; } /** * Import a flight, parse out the different rows * @param array $row * @param int $index * @return bool */ public function import(array $row, $index): bool { $subfleet = $this->getSubfleet($row['subfleet']); $row['subfleet_id'] = $subfleet->id; # Generate a hex code if(!$row['hex_code']) { $row['hex_code'] = ICAO::createHexCode(); } # Set a default status if($row['status'] === null) { $row['status'] = AircraftStatus::ACTIVE; } # Just set its state right now as parked $row['state'] = AircraftState::PARKED; # Try to add or update $aircraft = Aircraft::firstOrNew([ 'registration' => $row['registration'], ], $row); try { $aircraft->save(); } catch(\Exception $e) { $this->status = 'Error in row '.$index.': '.$e->getMessage(); return false; } $this->status = 'Imported '.$row['registration'].' '.$row['name']; return true; } }