예제 #1
0
 /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     switch ($this->method) {
         case 'GET':
         case 'DELETE':
         case 'POST':
             return Netblock::createRules($this);
         case 'PUT':
         case 'PATCH':
             return Netblock::updateRules($this);
         default:
             break;
     }
     return [];
 }
예제 #2
0
 /**
  * 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 Netblock|null $netblock */
     $netblock = Netblock::find($this->option('id'));
     if (null === $netblock) {
         $this->error('Unable to find netblock 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;
         }
         $netblock->contact()->associate($user);
     }
     $stringOptions = ["first_ip", "last_ip", "description"];
     foreach ($stringOptions as $option) {
         if (!empty($this->option($option))) {
             $netblock->{$option} = $this->option($option);
         }
     }
     if (!empty($this->option("enabled"))) {
         $netblock->enabled = castStringToBool($this->option("enabled"));
     }
     $validation = Validator::make($netblock->toArray(), Netblock::updateRules($netblock));
     if ($validation->fails()) {
         foreach ($validation->messages()->all() as $message) {
             $this->warn($message);
         }
         $this->error('Failed to create the netblock due to validation warnings');
         return false;
     }
     $netblock->save();
     $this->info("Netblock has been successfully updated");
     return true;
 }
예제 #3
0
 /**
  * {@inheritdoc}.
  */
 protected function getValidator($model)
 {
     $data = $this->getModelAsArrayForDirtyAttributes($model);
     $updateRules = $this->getUpdateRulesForDirtyAttributes(Netblock::updateRules($model));
     return Validator::make($data, $updateRules);
 }