webapix/laravel-mygls
A Laravel integration for the MyGLS API that lets you create parcels, print shipping labels, and track GLS deliveries directly from your application. It wraps common MyGLS operations in a simple, configurable package with a clean Laravel-friendly interface.
composer require webapix/laravel-myglsphp artisan vendor:publish --tag=mygls-config (check src/ for the exact tag — the package is small enough that the service provider is short)..env. MyGLS auth is username/password plus a clientNumber that identifies your GLS contract:
MYGLS_USERNAME=
MYGLS_PASSWORD=
MYGLS_CLIENT_NUMBER=
MYGLS_ENV=test # or prod
config/mygls.php for the binding name — the package is a thin wrapper around webapix/mygls-php, so most of the real API surface lives behind that client.Where to look first: this package is deliberately small. Read the service provider, the config file, and then jump to the underlying webapix/mygls-php SDK's README — the parcel DTOs, status enums, and endpoint methods are defined there, not here. The Laravel layer mostly gives you config-driven client construction and container bindings.
First use case: create a single parcel and print its label. Do this against the test environment first:
Order model and save the PDF to a private disk.Inject, don't resolve ad hoc. Bind the client once via the service provider and resolve it through the container. Facades are fine in controllers, but jobs and services should receive the client (or a small wrapper of your own) via constructor injection so you can swap it in tests.
Wrap the SDK, don't call it everywhere. Create a small GlsService/ParcelBuilder in your app that takes your Order model and returns a ready-to-send parcel DTO. The MyGLS DTOs are verbose and country-sensitive; keeping that mapping in one place pays off as soon as address formats, COD, or weight rules change.
Queue label generation and parcel creation. MyGLS responses can be slow (multiple seconds), and label endpoints do real work (PDF rendering). Do creation and label printing inside ShouldQueue jobs, and store the returned parcel number as the idempotency anchor on the order. Retry with a small backoff; do not retry blindly without an order-level lock, because a duplicate parcel in GLS is painful to clean up.
Batch labels at end-of-day. The common workflow is: orders get parcel numbers as they're placed, then a scheduled command asks MyGLS for PDFs for all the day's parcels and drops them in a single archive for the picker. Loop the label endpoint per parcel number; don't try to invent a "batch" call that doesn't exist.
Poll status on a schedule. Tracking isn't webhook-pushed by MyGLS. Run an everyFifteenMinutes command that takes recent parcel numbers and pulls status, then map the returned status codes onto your own order states. Cache the last known status so a flaky response doesn't roll an order backwards.
Schedule pickup once per day. The pickup endpoint is per-client and generally per-day. Make it idempotent by keying on date + client — calling it twice for the same day will either be rejected or create a duplicate.
Test with a fake. In tests, bind a stub implementation of the parcel client that returns canned responses. The package's config-driven construction makes this easy: override the binding in TestCase::setUp.
clientNumber is required on nearly every call. It's not derived from your username; you'll get cryptic auth errors if it's blank or mismatched with the environment.Content-Type: application/pdf when streaming to the browser. Streaming the raw string produces a corrupt download that looks like a corrupted PDF rather than an encoding bug.vendor/webapix/mygls-php/src directly — it's the authoritative reference for DTO fields and endpoint behaviour.How can I help you explore Laravel packages today?