Laravel: Publiq service class
Wrap the Publiq calls in an injectable service class, keeping the integration in one place.
Create app/Services/Publiq.php and inject it via the Laravel container:
<?php
namespace App\Services;
use Illuminate\Support\Facades\Http;
class Publiq
{
public function send(array $payload): array
{
return Http::withToken(env('PUBLIQ_API_KEY'))
->post('https://api.publiq.digital/v1/emails', $payload)
->throw()
->json();
}
}Best practices
- Always call Publiq from the server — the API key goes in the
Authorizationheader, never on the client. - On
429/5xx, retry with exponential backoff (respectRetry-After). - Prefer
templateKeyover inline HTML to keep content versioned. - Handle errors via the response
error.codefield — see Errors. - Send from a verified domain — see Domains.