/** * Execute the console command. * * @return mixed */ public function fire() { $user = new User(); $user->email = $this->argument('email'); $raw = ''; if (is_null($this->option('password'))) { $password = substr(sha1(time() . $this->argument('email')), 0, 9); $raw = $password; } else { $password = $this->option('password'); } $user->password = bcrypt($password); if (!is_null($this->option('name'))) { $user->name = $this->option('name'); } try { $user->save(); /* Assign as admin */ $this->info('The generated password is ' . $raw); } catch (QueryException $e) { $this->error("Failed to create user, possible reasons: table doesn't exists yet, or there is another user with the supplied email address"); } $user = User::where('email', $this->argument('email'))->firstOrFail(); try { $role = Role::where('root', true)->firstOrFail(); $user->assignRole($role); $this->info('User assigned to: ' . $role->name . ' role'); } catch (ModelNotFoundException $e) { $this->error('Administrator role not found'); $role = new Role(); $role->name = 'Admin'; $role->label = 'Administrators'; $role->root = true; $role->save(); $this->info('Role ' . $role->name . ' created with root access level'); $user->assignRole($role); $this->info('User assigned to: ' . $role->name . ' role'); } }