/** * Execute the console command. * * @return boolean */ public function handle() { if (empty($this->option('name')) || empty($this->option('description'))) { $this->error('Missing options for name and/or descrption'); return false; } $role = new Role(); $role->name = empty($this->option('name')) ? false : $this->option('name'); $role->description = empty($this->option('description')) ? false : $this->option('description'); $validation = Validator::make($role->toArray(), Role::createRules($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; } if (!$role->save()) { $this->error('Failed to save the role into the database'); return false; } $this->info("The role {$this->option('name')} has been created"); return true; }
/** * {@inheritdoc}. */ protected function getValidator($model) { return Validator::make($model->toArray(), Role::createRules()); }