PHPackages                             avraapi/laravel-sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. avraapi/laravel-sdk

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

avraapi/laravel-sdk
===================

Official Laravel integration package for the AvraAPI (APIX) enterprise API gateway. Provides a Service Provider, Facade, and config file for seamless Laravel 10/11/12 integration.

1.1.2(1mo ago)15MITPHPPHP ^8.2

Since Apr 4Pushed 1mo agoCompare

[ Source](https://github.com/avraapi/laravel-sdk)[ Packagist](https://packagist.org/packages/avraapi/laravel-sdk)[ RSS](/packages/avraapi-laravel-sdk/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (10)Versions (4)Used By (0)

AvraAPI Laravel SDK
===================

[](#avraapi-laravel-sdk)

Official Laravel integration package for the [AvraAPI (APIX)](https://avraapi.com) enterprise API gateway.

Provides a Service Provider, Facade, and config file for seamless Laravel 10/11/12 integration. Built on top of `avraapi/php-sdk`.

> **Full documentation &amp; guides:**

```
composer require avraapi/laravel-sdk
```

Quick Start
-----------

[](#quick-start)

The package auto-discovers via `extra.laravel` in `composer.json` — no manual registration needed.

### Publish Config

[](#publish-config)

```
php artisan vendor:publish --tag=avraapi-config
```

### Set Credentials

[](#set-credentials)

Add to your `.env`:

```
AVRAAPI_API_KEY=your-api-key
AVRAAPI_API_SECRET=your-api-secret
AVRAAPI_ENV=dev
```

### Use the Facade

[](#use-the-facade)

```
use Avraapi\Laravel\Facades\AvraAPI;

// IP geolocation
$geo = AvraAPI::location()->lookupIp('112.134.205.126');
echo $geo->data['country']; // 'Sri Lanka'

// SMS
AvraAPI::sms()->sendSingle('0771234567', 'Hello from AvraAPI!');

// QR code
AvraAPI::utilities()->generateQr('https://avraapi.com')->saveAs('/tmp/qr.png');
```

Services
--------

[](#services)

ServiceAccessorEndpointsLocation`AvraAPI::location()`IP geolocation lookupsSMS`AvraAPI::sms()`Single, bulk-same, bulk-different, balanceUtilities`AvraAPI::utilities()`QR codes, barcodes, **PDF generation**Security`AvraAPI::security()`VPN &amp; Proxy Shield, Burner Email DetectionCurrency`AvraAPI::currency()`Currency codes, live rates, pair rates, conversion---

PDF Generation
--------------

[](#pdf-generation)

### Basic HTML to PDF

[](#basic-html-to-pdf)

```
$html = 'Invoice #001Total: $99.00';
$response = AvraAPI::utilities()->generatePdf($html);
$response->saveAs(storage_path('app/invoices/invoice.pdf'));
```

### Landscape with Custom Margins

[](#landscape-with-custom-margins)

```
$response = AvraAPI::utilities()->generatePdf(
    html:        $html,
    pageSize:    'A4',
    orientation: 'landscape',
    margins:     ['top' => 20, 'right' => 25, 'bottom' => 20, 'left' => 25],
);
$response->saveAs(storage_path('app/reports/landscape.pdf'));
```

### Base64 JSON Response

[](#base64-json-response)

```
$response = AvraAPI::utilities()->generatePdf($html, responseType: 'base64');
$base64Pdf = $response->data['data'];
file_put_contents(storage_path('app/invoice.pdf'), base64_decode($base64Pdf));
```

---

Generating PDFs from Complex Templates (Base64 Mode)
----------------------------------------------------

[](#generating-pdfs-from-complex-templates-base64-mode)

When your HTML contains quotes, newlines, inline CSS, or special characters, JSON escaping can cause issues. **Base64 mode** solves this by encoding the HTML before transport.

### Option A: Use the `generatePdfFromBase64()` Helper (Recommended)

[](#option-a-use-the-generatepdffrombase64-helper-recommended)

The helper accepts **raw HTML** and encodes it automatically:

```
// Load a complex Blade-rendered template
$html = view('invoices.pdf-template', [
    'invoice' => $invoice,
    'items'   => $items,
])->render();

// The SDK Base64-encodes internally — no manual encoding needed
$response = AvraAPI::utilities()->generatePdfFromBase64($html);
$response->saveAs(storage_path('app/invoices/inv-' . $invoice->id . '.pdf'));

// With full options:
$response = AvraAPI::utilities()->generatePdfFromBase64(
    html:        $html,
    responseType: 'binary',
    pageSize:    'Letter',
    orientation: 'landscape',
    margins:     ['top' => 15, 'right' => 20, 'bottom' => 15, 'left' => 20],
    privacyMode: true,
);
$response->saveAs(storage_path('app/invoices/inv-' . $invoice->id . '.pdf'));
```

### Option B: Manual Base64 Encoding

[](#option-b-manual-base64-encoding)

If you need full control, encode the HTML yourself and set `isBase64: true`:

```
$html = view('invoices.pdf-template', $data)->render();

$response = AvraAPI::utilities()->generatePdf(
    html:     base64_encode($html),
    isBase64: true,
);
$response->saveAs(storage_path('app/invoices/invoice.pdf'));
```

### How It Works

[](#how-it-works)

1. The SDK sends the Base64 string in the `html` field with `is_base64: true`.
2. The server decodes the Base64 content before validation and rendering.
3. The **512 KB size limit** applies to the **decoded** HTML, not the encoded payload.

---

Saving Files to Disk
--------------------

[](#saving-files-to-disk)

`BinaryResponse` has a built-in `saveAs()` that creates directories automatically:

```
// Save with Laravel's storage_path helper:
$response = AvraAPI::utilities()->generatePdf($html);
$savedPath = $response->saveAs(storage_path('app/invoices/invoice.pdf'));
echo "Saved to: {$savedPath}";

// BinaryResponse also provides:
$response->body;         // Raw binary string
$response->contentType;  // 'application/pdf'
$response->size;         // Size in bytes
$response->isPdf();      // true
$response->toDataUri();  // 'data:application/pdf;base64,...'

// Stream in a controller response:
return response($response->body, 200, [
    'Content-Type'        => $response->contentType,
    'Content-Disposition' => 'attachment; filename="invoice.pdf"',
]);
```

---

VPN &amp; Proxy Shield
----------------------

[](#vpn--proxy-shield)

Detect VPNs, proxies, Tor exit nodes, iCloud Private Relay, and hosting/datacenter IPs.

```
use Avraapi\Laravel\Facades\AvraAPI;

$result = AvraAPI::security()->checkVpn('8.8.8.8');

echo $result->data['ip_address'];    // '8.8.8.8'
echo $result->data['is_vpn'];        // false
echo $result->data['is_proxy'];      // false
echo $result->data['is_tor'];        // false
echo $result->data['is_relay'];      // false
echo $result->data['is_hosting'];    // false
echo $result->data['country_code'];  // 'US'
echo $result->data['city'];          // 'Mountain View'
echo $result->data['network_name'];  // 'Google LLC'
echo $result->data['provider_name']; // 'vpnapi' or 'iplocate'

// Use in a middleware or controller:
$d = $result->data;
if ($d['is_vpn'] || $d['is_proxy'] || $d['is_tor']) {
    abort(403, 'VPN/Proxy access is not permitted.');
}
```

---

Burner Email Shield
-------------------

[](#burner-email-shield)

Detect temporary and disposable email addresses using a dual-list Redis lookup (7,000+ domains).

```
$result = AvraAPI::security()->checkBurnerEmail('user@mailinator.com');

echo $result->data['email'];             // 'user@mailinator.com'
echo $result->data['domain'];            // 'mailinator.com'
echo $result->data['is_valid_syntax'];   // true
echo $result->data['is_disposable'];     // true
echo $result->data['source'];            // 'global', 'custom', or 'none'
echo $result->data['execution_time_ms']; // 0.42

// Guard a registration form in a controller:
if ($result->data['is_disposable']) {
    return back()->withErrors(['email' => 'Disposable emails are not allowed.']);
}
```

---

Multi-Currency Rates &amp; Conversion
-------------------------------------

[](#multi-currency-rates--conversion)

Free currency exchange rate API — 160+ currencies, 2-hour cached rates, zero credit cost.

### Get All Currency Codes

[](#get-all-currency-codes)

```
$result = AvraAPI::currency()->getCodes();

echo $result->data['count']; // 161
foreach ($result->data['codes'] as $c) {
    echo "{$c['code']} — {$c['name']}\n"; // 'USD — United States Dollar'
}
```

### Get Latest Rates from a Base Currency

[](#get-latest-rates-from-a-base-currency)

```
$result = AvraAPI::currency()->getLatestRates('USD');

echo $result->data['base'];              // 'USD'
echo $result->data['last_updated'];      // '2025-05-10T...'
echo $result->data['rates']['EUR'];      // 0.89123456
echo $result->data['rates']['LKR'];      // 298.50000000
```

### Get Pair Rate

[](#get-pair-rate)

```
$result = AvraAPI::currency()->getPairRate('USD', 'EUR');

echo $result->data['rate'];         // 0.89123456
echo $result->data['last_updated']; // '2025-05-10T...'
```

### Convert an Amount

[](#convert-an-amount)

```
$result = AvraAPI::currency()->convert('USD', 'LKR', 100.00);

$d = $result->data;
echo "{$d['amount']} {$d['base']} = {$d['conversion_result']} {$d['target']}";
// "100 USD = 29850.000000 LKR"
```

---

Privacy Mode
------------

[](#privacy-mode)

For sensitive documents (invoices, contracts, PII), enable privacy mode to exclude HTML content from observability logs:

```
$response = AvraAPI::utilities()->generatePdf($html, privacyMode: true);
$response->saveAs(storage_path('app/confidential/report.pdf'));
```

---

Error Handling
--------------

[](#error-handling)

All SDK exceptions propagate through the Facade and can be caught in controllers or registered in Laravel's exception handler:

```
use Avraapi\Apix\Exceptions\ApixAuthenticationException;
use Avraapi\Apix\Exceptions\ApixInsufficientFundsException;
use Avraapi\Apix\Exceptions\ApixRateLimitException;
use Avraapi\Apix\Exceptions\ApixValidationException;
use Avraapi\Apix\Exceptions\ApixException;

try {
    $response = AvraAPI::utilities()->generatePdf($html);
    $response->saveAs(storage_path('app/invoice.pdf'));
} catch (ApixRateLimitException $e) {
    // HTTP 429 — retry later
    return back()->with('error', 'Rate limited. Please try again shortly.');
} catch (ApixInsufficientFundsException $e) {
    // HTTP 402 — top up wallet
    return back()->with('error', 'Insufficient balance.');
} catch (ApixValidationException $e) {
    // HTTP 422 — bad input
    return back()->withErrors($e->getValidationErrors());
} catch (ApixException $e) {
    // Catch-all
    report($e);
    return back()->with('error', 'PDF generation failed.');
}
```

### Registering in Laravel's Exception Handler

[](#registering-in-laravels-exception-handler)

```
// bootstrap/app.php (Laravel 11+) or app/Exceptions/Handler.php

use Avraapi\Apix\Exceptions\ApixValidationException;
use Avraapi\Apix\Exceptions\ApixException;

$exceptions->render(function (ApixValidationException $e) {
    return response()->json([
        'error'   => $e->getErrorCode(),
        'message' => $e->getMessage(),
        'fields'  => $e->getValidationErrors(),
    ], 422);
});

$exceptions->render(function (ApixException $e) {
    return response()->json([
        'error'      => $e->getErrorCode(),
        'message'    => $e->getMessage(),
        'request_id' => $e->getRequestId(),
    ], $e->getHttpStatus() ?: 500);
});
```

---

Documentation
-------------

[](#documentation)

For full API reference, usage guides, and interactive examples, visit:

****

---

License
-------

[](#license)

MIT — [Fidex Developers (Pvt) Ltd](https://avraapi.com)

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance89

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 83.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~17 days

Total

3

Last Release

55d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/de7ca516dc8da568b76f57ef9de8940bf1a0211b16cb671d440d83686db73ce3?d=identicon)[avraapi](/maintainers/avraapi)

---

Top Contributors

[![fidex-profile](https://avatars.githubusercontent.com/u/219648547?v=4)](https://github.com/fidex-profile "fidex-profile (5 commits)")[![avraapi](https://avatars.githubusercontent.com/u/269558072?v=4)](https://github.com/avraapi "avraapi (1 commits)")

---

Tags

qrlaravelpdfsdksmsbarcodefacadeapixapi-gatewayavraapi

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/avraapi-laravel-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/avraapi-laravel-sdk/health.svg)](https://phpackages.com/packages/avraapi-laravel-sdk)
```

###  Alternatives

[barryvdh/laravel-dompdf

A DOMPDF Wrapper for Laravel

7.4k99.4M385](/packages/barryvdh-laravel-dompdf)[barryvdh/laravel-snappy

Snappy PDF/Image for Laravel

2.8k26.5M51](/packages/barryvdh-laravel-snappy)[rockett/weasyprint

A feature-rich WeasyPrint wrapper for generating PDFs from HTML and CSS, with support for PDF/A, PDF/UA, attachments, and optional Laravel integration.

30224.7k](/packages/rockett-weasyprint)[linkxtr/laravel-qrcode

A clean, modern, and easy-to-use QR code generator for Laravel

3720.4k](/packages/linkxtr-laravel-qrcode)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
