New subfleet not being attached to an airline on import #479 (#505)

* Fix subfleet not being attached to an airline on creation in import #479

* Call airline name with optional() around subfleet

* Minor cleanup
This commit is contained in:
Nabeel S
2020-01-16 14:23:23 -05:00
committed by GitHub
parent 6fcbd603ba
commit d03a77bd4b
3 changed files with 14 additions and 9 deletions

View File

@@ -4,6 +4,7 @@ namespace App\Services\ImportExport;
use App\Contracts\ImportExport;
use App\Models\Aircraft;
use App\Models\Airline;
use App\Models\Enums\AircraftState;
use App\Models\Enums\AircraftStatus;
use App\Models\Subfleet;
@@ -32,7 +33,8 @@ class AircraftImporter extends ImportExport
];
/**
* Find the subfleet specified, or just create it on the fly
* Find the subfleet specified, or just create it on the fly and attach it to the
* first airline that's been found
*
* @param $type
*
@@ -40,11 +42,12 @@ class AircraftImporter extends ImportExport
*/
protected function getSubfleet($type)
{
$subfleet = Subfleet::firstOrCreate([
return Subfleet::firstOrCreate([
'type' => $type,
], ['name' => $type]);
return $subfleet;
], [
'name' => $type,
'airline_id' => Airline::where('active', true)->first()->id,
]);
}
/**