argument('name'); $error = $this->validateName($name); if ($error) { $this->error($error); return; } $apiKey = new ApiKey; $apiKey->name = $name; $apiKey->key = ApiKey::generate(); $apiKey->save(); $this->info('API key created'); $this->info('Name: ' . $apiKey->name); $this->info('Key: ' . $apiKey->key); } /** * Validate name * * @param string $name * @return string */ protected function validateName($name) { if (!ApiKey::isValidName($name)) { return self::MESSAGE_ERROR_INVALID_NAME_FORMAT; } if (ApiKey::nameExists($name)) { return self::MESSAGE_ERROR_NAME_ALREADY_USED; } return null; } }