composer require dinas/shipping-sdk-php guzzlehttp/guzzle php-http/guzzle7-adapter
AppServiceProvider):
public function boot()
{
$config = Dinas\ShippingSdk\Configuration::getDefaultConfiguration()
->setAccessToken(config('services.dinas.api_token'))
->setHost(config('services.dinas.api_host', 'https://shipping.dinas.jp'));
$this->app->singleton(Dinas\ShippingSdk\Api\CarsApi::class, function () use ($config) {
return new Dinas\ShippingSdk\Api\CarsApi(new GuzzleHttp\Client(), $config);
});
}
config/services.php:
'dinas' => [
'api_token' => env('DINAS_API_TOKEN'),
'api_host' => env('DINAS_API_HOST', 'https://shipping.dinas.jp'),
],
Inject the API client into a controller or service and fetch cars:
public function index(Dinas\ShippingSdk\Api\CarsApi $carsApi)
{
$cars = $carsApi->getCars(
status: 'active',
per_page: 10
);
return view('cars.index', compact('cars'));
}
Use Laravel’s DI container to inject API clients into controllers/services:
public function __construct(
private Dinas\ShippingSdk\Api\CarsApi $carsApi,
private Dinas\ShippingSdk\Api\WebhooksApi $webhooksApi
) {}
Process paginated responses with Laravel collections:
$cars = collect([]);
$page = 1;
do {
$response = $carsApi->getCars(per_page: 100, page: $page);
$cars->push(...$response->getData());
$page = $response->getMeta()->getCurrentPage() + 1;
} while ($page <= $response->getMeta()->getTotalPages());
Centralize API error handling in a middleware or service:
try {
$carsApi->syncCars($carData);
} catch (Dinas\ShippingSdk\ApiException $e) {
Log::error('Dinas API Error: ' . $e->getMessage());
return back()->with('error', 'Failed to sync car');
}
Register webhooks in Laravel’s boot() method:
public function boot()
{
$webhook = new \Dinas\ShippingSdk\Model\Webhook(
name: 'car_arrival',
url: route('webhooks.car_arrival'),
events: ['car.arrived']
);
$this->webhooksApi->storeWebhook($webhook);
}
Upload car photos/documents using Laravel’s Storage facade:
$filePath = storage_path('app/car_photos/photo.jpg');
$file = fopen($filePath, 'r');
$apiInstance->storeCarPhotoFiles(
new \Dinas\ShippingSdk\Model\AlbumFiles(
car_id: 123,
files: [$file]
)
);
Use Laravel’s Bus facade to queue API calls:
Bus::dispatch(new SyncCarsJob($carData));
env() or Vault).DinasTokenService to handle token refresh if needed.throttle middleware:
Route::middleware(['throttle:10,1'])->group(function () {
// Dinas API routes
});
CarData). Map them to Laravel Eloquent models:
$car = (new Car)->fill([
'chassis' => $apiCar->getChassis(),
'make' => $apiCar->getMake(),
// ...
]);
ValidateWebhookPayload middleware:
public function handle(Request $request, Closure $next)
{
$request->validate([
'event' => 'required|in:car.arrived,car.shipped',
'data' => 'required|array',
]);
return $next($request);
}
DEBUG constant in Configuration:
$config->setDebug(true);
tap() to log responses:
$carsApi->getCars()->tap(function ($response) {
Log::debug('Dinas API Response:', $response->toArray());
});
multipart/form-data).
Use Laravel’s File facade to handle uploads:
$file = new File($filePath);
$apiInstance->storeCarPhotoFiles(new \Dinas\ShippingSdk\Model\AlbumFiles(
car_id: 123,
files: [$file]
));
page and per_page, not offset. Avoid mixing Laravel’s cursor() with this SDK.ngrok or Laravel’s queue:work:
php artisan webhooks:test car_arrival
Http client for consistency:
$client = new \Illuminate\Http\Client\PendingRequest();
$apiInstance = new Dinas\ShippingSdk\Api\CarsApi($client, $config);
retry helper for transient failures:
retry(3, function () use ($carsApi) {
return $carsApi->getCars();
}, 100);
cache() helper:
return Cache::remember('dinas_cars_active', now()->addHours(1), function () use ($carsApi) {
return $carsApi->getCars(status: 'active');
});
How can I help you explore Laravel packages today?