Exemple #1
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;
 }
Exemple #2
0
 /**
  * {@inheritdoc }
  */
 protected function getObjectByArguments()
 {
     return Netblock::find($this->argument("id"));
 }
Exemple #3
0
 /**
  * {@inheritdoc}.
  */
 protected function getModelFromRequest()
 {
     return Netblock::find($this->argument('id'));
 }