1. Go to this page and download the library: Download flairuk/laravel-all-aboard library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
flairuk / laravel-all-aboard example snippets
use FLAIRUK\AllAboard\Facades\AllAboard;
$response->data(); // the result, e.g. the booking or the list of journeys
$response->get('totalPrice.amount');
$response->toArray(); // the whole GraphQL body
foreach ($response as $item) { /* journeys, offers, locations… */ }
count($response);
$response['id']; // fields of a single result
$response[0]['id']; // entries of a list
AllAboard::locations()->search('koln'); // finds Köln; most relevant first
AllAboard::locations()->near(48.8566, 2.3522, radius: 10_000);
AllAboard::locations()->list(['countryCode' => 'FR', 'isMeta' => true])->lazy();
$journeys = AllAboard::journeys()->search('Sb0ISveC', 'p6fERure', '2026-11-01'); // London to Rome
foreach ($journeys as $journey) {
$journey['id'];
$journey['__typename']; // SmartJourney, NonStopJourney or BlueprintJourney
$journey['itinerary']; // SegmentCollections (trains) and Stopovers
}
AllAboard::journeys()->search($origin, $destination, now()->addMonth(), [
'filter' => ['types' => ['NON_STOP']], // SMART (default), NON_STOP or BLUEPRINT
'via' => [['uid' => 'ObB7ATsZ', 'duration' => new DateInterval('P2D')]], // two nights in Zürich
'passengers' => ['adult'],
'currency' => 'GBP',
]);
AllAboard::journeys()->ratings([$journeyA, $journeyB]); // [0.92, 0.71]: 1 is best
AllAboard::journeys()->blueprint($blueprintId, '2026-11-01');
$offer = AllAboard::journeys()->offer($journeyId, [
['type' => 'ADULT'],
['type' => 'YOUTH', 'age' => 22], // youth and senior passengers need an age or birthDate
]);
foreach ($offer['itinerary'] as $part) {
if ($part['__typename'] === 'SegmentCollection') {
$part['status']; // SUCCESS, or why this part couldn't be priced
$part['offers']; // id, price, parts (flexibility, classes, conditions)…
}
}
use FLAIRUK\AllAboard\Fields;
AllAboard::journeys()->search($from, $to, $date, ['passengers' => ['adult']], fields: Fields::JOURNEY.' itinerary { ... on SegmentCollection { availability { status priceFrom { '.Fields::MONEY.' } } } }');
AllAboard::orders()->find($orderId, fields: 'id status reference');
$booking = AllAboard::bookings()->create([$offerId], [['type' => 'ADULT'], ['type' => 'YOUTH', 'age' => 22]]);
$booking->get(' [
[
'id' => $booking->get('passengers.0.id'),
'firstName' => 'Jane',
'lastName' => 'Doe',
'email' => '[email protected]',
'tel' => '+441234567890',
'isContactPerson' => true, // one passenger must be the contact, with email and tel
],
['id' => $booking->get('passengers.1.id'), 'firstName' => 'Sam', 'lastName' => 'Doe', 'birthDate' => '2004-03-09'],
]);
$order = AllAboard::orders()->create($booking['id'], ['customer_id' => $customer->id]); // up to 30 seconds
// Wallet or invoice: complete it yourself
AllAboard::orders()->finalize($order['id']);
// Payment gateway: send the customer to All Aboard's hosted payment page
$payment = AllAboard::orders()->createPayment(
$order['id'],
successUrl: route('trains.done', $order['id']),
cancelUrl: route('trains.checkout'),
language: 'en',
);
return redirect($payment['url']); // the order is finalized automatically once they pay
AllAboard::bookings()->selectOffers($bookingId, [$flexibleOfferId]); // a different fare
AllAboard::bookings()->selectPlaceProperties($bookingId, $partId, [$propertyId => $optionId]); // window seat, lower berth…
AllAboard::bookings()->setTicketDelivery($offerId, 'TICKET_ON_DEPARTURE'); // where the offer allows it
AllAboard::bookings()->find($bookingId);
$order = AllAboard::orders()->find($orderId);
$order['status']; // PENDING, CONFIRMED, FAILED, REFUNDED…
$tickets = AllAboard::orders()->tickets($orderId);
foreach ($tickets as $ticket) {
match ($ticket['__typename']) {
'PdfTicket', 'FileResource' => $ticket['url'],
'CheckInResource' => $ticket['url'], // the passenger checks in online
'TicketOnDeparture' => $ticket['reference'], // collect from a station machine
'PassCode' => $ticket['code'], // activate in the pass provider's app
default => null,
};
}
$items = AllAboard::refunds()->refundable($orderId); // what can be refunded, and for how much
AllAboard::refunds()->refund($orderId, [$items[0]['id']]);
AllAboard::refunds()->list($orderId); // each refund's state: PENDING, SUCCEEDED or ERROR
$token = AllAboard::accessTokens()->create($orderId, ['READ', 'WRITE'], ttlSeconds: 900);
$token['token']; // the secret, returned only this once
$bundles = AllAboard::passes()->bundles(
[['type' => 'ADULT', 'nationality' => 'GB', 'countryResidence' => 'GB']],
['product' => 'interrail-global-pass', 'class' => '1stclass'],
);
AllAboard::passes()->forJourneyOffer($journeyOfferId, ['adult']); // passes valid for a priced journey
AllAboard::passes()->campaigns(); // codes to pass as 'campaignCode'
$booking = AllAboard::bookings()->createForPassBundle($bundles[0]['id'], [['birthDate' => '1980-02-15']]);
// updatePassengers(), orders()->create(), then finalize() or createPayment()
use FLAIRUK\AllAboard\Exceptions\AllAboardException;
use FLAIRUK\AllAboard\Exceptions\AuthenticationException;
use FLAIRUK\AllAboard\Exceptions\RateLimitException;
use FLAIRUK\AllAboard\Exceptions\TimeoutException;
try {
AllAboard::bookings()->create($offerIds, $passengers);
} catch (RateLimitException $e) {
// wait $e->retryAfter() seconds
} catch (AuthenticationException $e) {
// missing or rejected key, or a key without the scope this needs
} catch (TimeoutException $e) {
// an operator didn't answer in time: the work may still have completed, so re-read before retrying
} catch (AllAboardException $e) {
if ($e->hasCode('NO_TICKETS', 'PRICE_CHANGED', 'OFFER_SET_UNAVAILABLE')) {
// get a fresh offer and try again
}
if ($e->hasCode('TRAVEL_CARD_FIELD_REQUIRED')) {
$e->args('TRAVEL_CARD_FIELD_REQUIRED')['field']; // e.g. "identifier": ask for it and book again
}
$e->codes(); // e.g. ['NO_TICKETS']
$e->errors; // the raw GraphQL errors
$e->requestId; // quote this to All Aboard support
$e->data(); // any partial data that came back
}