encrypter = $encrypter; $this->repository = $repository; } /** * Create a new API key for the Panel using the permissions passed in the data request. * This will automatically generate an identifer and an encrypted token that are * stored in the database. * * @param array $data * @return \Pterodactyl\Models\ApiKey * * @throws \Pterodactyl\Exceptions\Model\DataValidationException */ public function handle(array $data): ApiKey { $data = array_merge($data, [ 'identifier' => str_random(ApiKey::IDENTIFIER_LENGTH), 'token' => $this->encrypter->encrypt(str_random(ApiKey::KEY_LENGTH)), ]); $instance = $this->repository->create($data, true, true); return $instance; } }