Clean UserTableSeeder (#420)

This commit is contained in:
bdgold 2016-09-05 10:35:13 -04:00 committed by Phan An
parent ddb83d5c3e
commit 5d9a2ffe73

View file

@ -10,22 +10,27 @@ class UserTableSeeder extends Seeder
*/
public function run()
{
if (!config('koel.admin.name') ||
!config('koel.admin.email') ||
!config('koel.admin.password')) {
$this->command->error('Please fill in initial admin details in .env file first.');
abort(422);
}
User::create([
'name' => config('koel.admin.name'),
'email' => config('koel.admin.email'),
'password' => Hash::make(config('koel.admin.password')),
User::create($this->getUserDetails() + [
'is_admin' => true,
]);
if (app()->environment() !== 'testing') {
if (!app()->runningUnitTests()) {
$this->command->info('Admin user created. You can (and should) remove the auth details from .env now.');
}
}
protected function getUserDetails()
{
$details = array_filter(array_only(config('koel.admin', []), [
'name', 'email', 'password',
]));
if (count($details) !== 3) {
$this->command->error('Please fill in initial admin details in .env file first.');
abort(422);
}
return $details;
}
}