Rename 'Airlines' model to 'Airline'

This commit is contained in:
Nabeel Shahzad
2017-06-19 11:50:25 -05:00
parent 6ef83084d1
commit c732476f6d
19 changed files with 94 additions and 84 deletions

View File

@@ -1,10 +0,0 @@
<?php
$factory->define(App\Models\AircraftClass::class, function (Faker\Generator $faker) {
return [
'id' => 1,
'code' => 'H',
'name' => 'Heavy',
'notes' => 'Heavy aircraft',
];
});

View File

@@ -1,10 +0,0 @@
<?php
$factory->define(App\Models\Fare::class, function (Faker\Generator $faker) {
return [
'code' => 'Y',
'name' => 'Economy',
'price' => '100',
'capacity' => '200',
];
});

View File

@@ -1,10 +0,0 @@
<?php
$factory->define(App\Models\Flight::class, function (Faker\Generator $faker) {
return [
'code' => 'Y',
'name' => 'Economy',
'price' => '100',
'capacity' => '200',
];
});

View File

@@ -12,7 +12,35 @@ class DatabaseSeeder extends Seeder
*/
public function run()
{
$this->seed_from_yaml(App::environment());
}
protected function seed_from_yaml($env): void
{
$path = database_path('seeds/'.$env.'.yml');
$time_fields = ['created_at', 'updated_at'];
$curr_time = Carbon::now('UTC')->format('Y-m-d H:i:s');
$yml = Yaml::parse(file_get_contents($path));
foreach ($yml as $table => $rows) {
foreach ($rows as $row) {
# encrypt any password fields
if (array_key_exists('password', $row)) {
$row['password'] = bcrypt($row['password']);
}
# if any time fields are == to "now", then insert the right time
foreach ($time_fields as $tf) {
if (array_key_exists($tf, $row) && $row[$tf] === 'now') {
$row[$tf] = $curr_time;
}
}
DB::table($table)->insert($row);
}
}
}
}