1. Go to this page and download the library: Download nikba/laravel-bussystem-api 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/ */
nikba / laravel-bussystem-api example snippets
use Nikba\LaravelBussystemApi\Data\SearchCriteria;
use Nikba\LaravelBussystemApi\Enums\SortType;
use Nikba\LaravelBussystemApi\Facades\BusSystem;
$criteria = SearchCriteria::create()
->date('2026-09-15')
->from(3)
->to(7)
->bus()
->directOnly()
->sortBy(SortType::Price)
->currency('EUR')
->language('en');
$routes = BusSystem::getRoutes($criteria);
use Nikba\LaravelBussystemApi\Contracts\BusSystemClientInterface;
use Nikba\LaravelBussystemApi\Data\SearchCriteria;
final class SearchRoutes
{
public function __construct(
private readonly BusSystemClientInterface $busSystem,
) {}
public function handle(int $fromCityId, int $toCityId, string $date): array
{
return $this->busSystem->getRoutes(
SearchCriteria::create()
->date($date)
->from($fromCityId)
->to($toCityId),
);
}
}
use Nikba\LaravelBussystemApi\Enums\SortType;
use Nikba\LaravelBussystemApi\Enums\TransportType;
$criteria
->transport(TransportType::Train)
->sortBy(SortType::Time);
use Illuminate\Support\Facades\Log;
use Nikba\LaravelBussystemApi\Exceptions\BusSystemApiException;
use Nikba\LaravelBussystemApi\Exceptions\BusSystemAuthenticationException;
use Nikba\LaravelBussystemApi\Exceptions\BusSystemException;
use Nikba\LaravelBussystemApi\Exceptions\BusSystemValidationException;
try {
$routes = BusSystem::getRoutes($criteria);
} catch (BusSystemAuthenticationException $exception) {
report($exception);
abort(502, 'BusSystem authentication failed.');
} catch (BusSystemValidationException $exception) {
return response()->json([
'message' => $exception->getMessage(),
'context' => $exception->getContext(),
], 422);
} catch (BusSystemApiException $exception) {
Log::warning('BusSystem request failed', [
'message' => $exception->getMessage(),
]);
abort(503, 'The transport service is temporarily unavailable.');
} catch (BusSystemException $exception) {
report($exception);
abort(500);
}
use Nikba\LaravelBussystemApi\Enums\OrderStatus;
use Nikba\LaravelBussystemApi\Models\Order;
$order = Order::create([
'order_id' => $response['order_id'],
'security_code' => $response['security'],
'status' => $response['status'],
'currency' => 'EUR',
'api_response' => $response,
]);
$activeOrders = Order::query()->active()->get();
$paidOrders = Order::query()->paid()->get();
if ($order->status() === OrderStatus::Buy) {
// The order is paid.
}
use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use Nikba\LaravelBussystemApi\Services\BusSystemClient;
$handler = new MockHandler([
new Response(200, [], json_encode(['status' => 'ok'], JSON_THROW_ON_ERROR)),
]);
$client = new BusSystemClient(
apiUrl: 'https://example.test',
login: 'test-login',
password: 'test-password',
httpClient: new Client(['handler' => HandlerStack::create($handler)]),
);
$response = $client->ping();