/** * Execute the console command. * * @return mixed */ public function handle() { $name = $this->argument('name'); $role = $this->loadRole($name, true); if ($role != null) { return; } $displayName = $this->argument('display_name'); $description = $this->argument('description'); Role::create([Role::PROPERTY_NAME => $name, Role::PROPERTY_DISPLAY => $displayName, Role::PROPERTY_DESC => $description]); $this->info("Successfully created the role '{$name}'."); }
/** * Loads Role based upon name * * @param $name * @param bool $failOnSuccess * @return null|Role */ protected function loadRole($name, $failOnSuccess = false) { $role = Role::query()->where(Role::PROPERTY_NAME, $name)->first(); if ($role == null) { if ($failOnSuccess) { return null; } $this->error("The Entrust role '{$name}' does not exist."); } elseif ($failOnSuccess) { $this->error("The Entrust role '{$name}' already exists."); } return $role; }
/** * Execute the console command. * * @return mixed */ public function handle() { $headers = ['Name', 'Display Name', 'Description', 'Id']; $roles = Role::all([Role::PROPERTY_NAME, Role::PROPERTY_DISPLAY, Role::PROPERTY_DESC, Role::PROPERTY_KEY])->toArray(); $this->table($headers, $roles); }