role = $this->option('role'); if ($user->role ) { if (!in_array($user->role , User::$roles)) { $this->error('Invalid role'); return false; } } else { $user->role = $this->ask('User role (admin/user)', 'admin'); while (!in_array($user->role, User::$roles)) { $this->error('Invalid role'); $user->role = $this->ask('Please enter valid role'); } } $user->role = array_flip(User::$roles)[$user->role]; $user->first_name = $this->option('firstName') ? $this->option('firstName') : $this->ask('User first name'); $user->last_name = $this->option('lastName') ? $this->option('lastName') : $this->ask('User last name'); $user->email = $this->option('email'); if ($user->email) { if (!filter_var($user->email, FILTER_VALIDATE_EMAIL)) { $this->error('Invalid email address'); return false; } } else { $user->email = $this->ask('User email address'); while (!filter_var($user->email, FILTER_VALIDATE_EMAIL)) { $this->error('Incorrect email address'); $user->email = $this->ask('Please enter valid email address'); } } $user->password = \Hash::make($this->option('password') ? $this->option('password') : $this->secret('User password')); if ($this->confirm('Do you want to create the user?', true)) { if ($user->isAdmin()) { $user->invite_state = User::INVITE_STATE_ACTIVATED; } try { $user->save(); } catch (\Exception $e) { $this->line($e->getMessage()); $this->error('User already exists.'); return false; } } $this->info('User created with id: '.$user->id); return true; } }