Documentation menu

SDKs

PHP & Laravel SDK

The official Wayline SDK for PHP & Laravel: PHP 8.1+. PSR-18 HTTP client and PSR-17 factories (bring your own, e.g. Guzzle). Laravel service provider and facade included.

Install

Packagist
composer require wayline/wayline-php

Quickstart

Set WAYLINE_API_KEY to a test key (see the Quickstart), then:

PHP & Laravel
<?php
use Wayline\Client;

$wayline = new Client(getenv('WAYLINE_API_KEY'));

$d = $wayline->distance([
    'origin' => ['lat' => 23.7925, 'lng' => 90.4078],
    'destination' => '23.733,90.4172',
    'units' => 'imperial',
]);
echo $d['distance_miles'], ' mi, ', $d['duration_seconds'], " s\n";

// Laravel: set WAYLINE_API_KEY in .env, then
// use Wayline\Laravel\Facades\Wayline;
// Wayline::matrix(['origins' => [...], 'destinations' => [...]]);

Errors

Non-2xx responses raise a typed error after retries are exhausted. Branch on code — the full list is in the error reference.

Error handling
use Wayline\WaylineException;

try {
    $wayline->distance(['origin' => '0,0', 'destination' => '0,1']);
} catch (WaylineException $e) {
    echo $e->errorCode, ' ', $e->status, ' ', $e->requestId;
}

Configuration

OptionDefaultDescription
API keyWAYLINE_API_KEYYour live or test key. Never logged.
Base URLhttps://api.wayline.cloudOverride for staging or a proxy.
Timeout30 secondsPer attempt.
Max retries3For 429 and 5xx, with exponential backoff + jitter, honoring Retry-After.

Source and releases

Package: wayline/wayline-php on Packagist. Source: packages/sdk-php. Versions follow semantic versioning; see the CHANGELOG in the package and our product changelog.

Was this page helpful?