create($attrs); if(!empty($subfleet_ids)) { $rank->subfleets()->syncWithoutDetaching($subfleet_ids); } return $rank; } /** * Create a subfleet with a number of aircraft assigned * @param null $aircraft_count * @return mixed */ public static function createSubfleetWithAircraft($aircraft_count = null) { $subfleet = factory(\App\Models\Subfleet::class)->create(); if($aircraft_count === null) { $aircraft_count = \random_int(2, 10); } $aircraft = factory(\App\Models\Aircraft::class, $aircraft_count)->create([ 'subfleet_id' => $subfleet->id ]); return [ 'subfleet' => $subfleet, 'aircraft' => $aircraft, ]; } }