sashalenz / nhtsa-api
Laravel integration package for the NHTSA vPIC API.
Installs: 4
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/sashalenz/nhtsa-api
Requires
- php: ^8.4
- illuminate/http: ^12.0
- illuminate/support: ^12.0
- spatie/laravel-data: ^4.5
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- orchestra/testbench: ^9.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-laravel: ^2.3
- spatie/laravel-ray: ^1.36
README
Laravel package that integrates with the NHTSA vPIC API providing DTO-based helpers for VIN and WMI decoding.
Installation
composer require sashalenz/nhtsa-api
If you are developing locally as part of this monorepo, ensure the path repository is registered in the root composer.json and run:
./vendor/bin/sail composer update sashalenz/nhtsa-api
Optionally publish the configuration:
php artisan vendor:publish --tag="nhtsa-api-config"
Usage
use Sashalenz\NhtsaApi\Data\Requests\DecodeVinRequestData; use Sashalenz\NhtsaApi\Facades\NhtsaApi; $response = NhtsaApi::decodeVin(DecodeVinRequestData::from([ 'vin' => '5UXWX7C5*BA', 'modelYear' => 2011, ])); $make = $response->variables()->first()?->value;
Available façade methods:
decodeVin– повертає класичні змінні VIN (Make, Model, Body Class тощо) у вигляді колекціїVinDecodedVariableDataв документації позначено як Decode VIN.decodeVinExtended– доповнена версія з додатковими полями (зокрема дані NCSA), також повертаєVinDecodedVariableData.decodeVinValues– повертає «плоский» результат у форматі ключ-значення (VinDecodeFlatResponseData), зручний для швидкого доступу до атрибутів.decodeVinValuesExtended– «плоский» розширений варіант з додатковими змінними, аналогічнийdecodeVinValues.decodeWmi– розшифровка WMI (World Manufacturer Identifier) та пов’язані метадані у виглядіDecodeWmiResponseData.
Each method accepts the relevant Data DTO request and returns a typed response DTO wrapping the API payload.
Service layer with history logging
use Sashalenz\NhtsaApi\Data\Requests\DecodeVinRequestData; use Sashalenz\NhtsaApi\Services\NhtsaApiService; $service = app(NhtsaApiService::class); $make = $service->determineMake(DecodeVinRequestData::from([ 'vin' => 'WP0AA2A7GL', 'modelYear' => 2016, ])); $requests = $service->getVinRequestCount('WP0AA2A7GL');
Кожен запит логуються у таблицю nhtsa_api_requests із полями VIN, Vehicle Descriptor, Make, Model, Model Year, JSON значеннями та morph-зв’язком із ініціатором.
Testing
./vendor/bin/sail test packages/nhtsa-laravel-api
When Docker is not available, run the tests within your Sail environment before committing changes.