phpvms/app/Database/seeds/DatabaseSeeder.php

38 lines
832 B
PHP
Raw Normal View History

2017-06-09 02:28:26 +08:00
<?php
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Map these other environments to a specific seed file
* @var array
*/
public static $seed_mapper = [
'local' => 'dev',
'qa' => 'dev',
'staging' => 'dev',
];
2017-06-09 02:28:26 +08:00
/**
* Run the database seeds.
*/
public function run()
{
$env = App::environment();
2017-12-05 05:52:57 +08:00
if(array_key_exists($env, self::$seed_mapper)) {
$env = self::$seed_mapper[$env];
}
2017-06-20 00:50:25 +08:00
$path = database_path('seeds/'.$env.'.yml');
print("Seeding seeds/$env.yml\n");
if(!file_exists($path)) {
$path = database_path('seeds/prod.yml');
2017-06-20 00:50:25 +08:00
}
$svc = app('App\Services\DatabaseService');
2017-06-25 02:20:24 +08:00
$svc->seed_from_yaml_file($path);
}
2017-06-09 02:28:26 +08:00
}