/** * Execute the console command. * * @return boolean */ public function handle() { if (empty($this->option('role'))) { $this->warn('the required role argument was not passed, try --help'); return false; } $role = false; if (!is_object($role)) { $role = Role::where('name', $this->option('role'))->first(); } if (!is_object($role)) { $role = Role::find($this->option('role')); } if (!is_object($role)) { $this->error('Unable to find role with this criteria'); return false; } // Apply changes to the role object if (!empty($this->option('name'))) { $role->name = $this->option('name'); } if (!empty($this->option('description'))) { $role->description = $this->option('description'); } $validation = Validator::make($role->toArray(), Role::updateRules($role)); if ($validation->fails()) { foreach ($validation->messages()->all() as $message) { $this->warn($message); } $this->error('Failed to create the role due to validation warnings'); return false; } // Save the object $role->save(); $this->info("Role has been successfully updated"); return true; }
/** * {@inheritdoc}. */ protected function getValidator($model) { $data = $this->getModelAsArrayForDirtyAttributes($model); $updateRules = $this->getUpdateRulesForDirtyAttributes(Role::updateRules($model)); return Validator::make($data, $updateRules); }