<?php

use App\Role;
use App\User;
use Illuminate\Database\Seeder;

class UsersSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $this->addAdminUser();
    }

    /**
     * Adds admin user specified in config
     */
    protected function addAdminUser()
    {
        // If there is a user with specified email, just update the record, else create it
        $user = User::updateOrCreate(
            [
                'email' => config('admin.email', 'mail@jkozlovsky.cz')
            ],
            [
                'name' => config('admin.name', 'Administrator'),
                'password' => bcrypt(config('admin.password', "123456"))
            ]
        );

        $user->attachRole(Role::ADMIN_ID);
    }
}
