Cleanup Exporter; use firstOrCreate for any missing data we can infer/setup defaults for

This commit is contained in:
Nabeel Shahzad
2018-03-22 12:43:58 -05:00
parent 9657e8bd40
commit fbfd71adcf
11 changed files with 58 additions and 49 deletions

View File

@@ -10,6 +10,7 @@ use App\Models\Airline;
*/
class ImportExport
{
public $assetType;
public $status;
/**
@@ -18,13 +19,17 @@ class ImportExport
public static $columns = [];
/**
* Get the airline from the ICAO
* Get the airline from the ICAO. Create it if it doesn't exist
* @param $code
* @return \App\Models\Airline
* @return \Illuminate\Database\Eloquent\Model
*/
public function getAirline($code)
{
return Airline::where('icao', $code)->first();
$airline = Airline::firstOrCreate([
'icao' => $code,
], ['name' => $code]);
return $airline;
}
/**