Ejemplo n.º 1
0
 /**
  * Execute the console command.
  *
  * @return boolean
  */
 public function handle()
 {
     $netblock = new Netblock();
     $contact = $this->findUserByIdOrEmail($this->option("contact"));
     if (null === $contact) {
         $this->error("Failed to find contact, could\\'nt save netblock");
         return false;
     }
     $netblock->contact()->associate($contact);
     $netblock->first_ip = $this->option('first_ip');
     $netblock->last_ip = $this->option('last_ip');
     $netblock->description = $this->option('description');
     $netblock->enabled = $this->option('enabled') === "true" ? true : false;
     $validation = Validator::make($netblock->toArray(), Netblock::createRules($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;
     }
     if (!$netblock->save()) {
         $this->error('Failed to save the netblock into the database');
         return false;
     }
     $this->info("The netblock has been created");
     return true;
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}.
  */
 protected function getModelFromRequest()
 {
     $netblock = new Netblock();
     $netblock->contact()->associate(User::find($this->argument('contact')));
     $netblock->first_ip = $this->argument('first_ip');
     $netblock->last_ip = $this->argument('last_ip');
     $netblock->description = $this->argument('description');
     $netblock->enabled = $this->argument('enabled') === 'true' ? true : false;
     return $netblock;
 }