username = ($this->argument('username') === null) ? $this->ask('User name: ') : $this->argument('username'); $user->email = ($this->argument('email') === null) ? $this->ask('User email: ') : $this->argument('email'); $user->password = ($this->argument('password') === null) ? Hash::make($this->ask('User password: ')) : Hash::make($this->argument('password')); if ($this->option('force') === true || $this->confirm('Save this user?', true)) { $exists = (new $class)->where([ 'username' => $user->username, 'email' => $user->email, ])->first(); if ($exists === null) { // user is not exisiting yet, just create him and return $user->save(); $this->info('Created a user with id: '.$user->id); return self::E_OK; } // user is already existing, check the input and handle if ($this->option('force')) { if ($exists->update($user->getAttributes())) { $this->info('Updated an existing user with id: '.$exists->id); return self::E_OK; } $this->warn('Updating an existing user with id: '.$exists->id.' ended with errors'); return self::E_UPDATING_FAILED; } $this->error('User already exist with id: '.$exists->id); return self::E_USER_EXISTS; } return self::E_CHAOS; // default end with an error to show, that this line was hit accidentially } }