コード例 #1
0
ファイル: EditCommand.php プロジェクト: ihatehandles/AbuseIO
 /**
  * {@inheritdoc}.
  */
 protected function getValidator($model)
 {
     if (null !== $model) {
         $data = $this->getModelAsArrayForDirtyAttributes($model);
         $updateRules = $this->getUpdateRulesForDirtyAttributes(Domain::updateRules($model));
         return Validator::make($data, $updateRules);
     }
     return false;
 }
コード例 #2
0
 /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     switch ($this->method) {
         case 'GET':
             break;
         case 'DELETE':
             break;
         case 'POST':
             return Domain::createRules();
         case 'PUT':
             break;
         case 'PATCH':
             return Domain::updateRules($this);
         default:
             break;
     }
     return [];
 }
コード例 #3
0
ファイル: EditCommand.php プロジェクト: yoimbert/AbuseIO
 /**
  * Execute the console command.
  *
  * @return boolean
  */
 public function handle()
 {
     if (empty($this->option('id'))) {
         $this->warn('The required id argument was not passed, try --help');
         return false;
     }
     /** @var Domain|null $domain */
     $domain = Domain::find($this->option('id'));
     if (null === $domain) {
         $this->error('Unable to find domain with this criteria');
         return false;
     }
     if (!empty($this->option("contact"))) {
         /** @var User|null $user */
         $user = User::find($this->option('contact')) ?: User::where('email', '=', $this->option("contact"))->first();
         if (null === $user) {
             $this->error("Unable to find contact with this criteria");
             return false;
         }
         $domain->contact()->associate($user);
     }
     if (!empty($this->option("name"))) {
         $domain->name = $this->option("name");
     }
     if (!empty($this->option("enabled"))) {
         $domain->enabled = castStringToBool($this->option("enabled"));
     }
     $validation = Validator::make($domain->toArray(), Domain::updateRules($domain));
     if ($validation->fails()) {
         foreach ($validation->messages()->all() as $message) {
             $this->warn($message);
         }
         $this->error('Failed to create the domain due to validation warnings');
         return false;
     }
     $domain->save();
     $this->info("Domain has been successfully updated");
     return true;
 }