Laravel wrapper for the Dutch open mobility data. Basic Vehicle Registration All non-sensitive data of the Dutch vehicle fleet.
Laravel application to get vehicle information from opendata.rdw.nl or overheid.io.
This package extends jdkweb/rdw-api to be used in Filament.
Depends on:
Github: jdkweb/rdw-api
packagist: jdkweb/rdw-api
Requires PHP 8.1 and Laravel 10 and Filament 3.0 or higher
Install the package via composer:
composer require jdkweb/rdw-api-filament
Translations available:
See:
Github: jdkweb/rdw-api
Packagist: jdkweb/rdw-api
use Jdkweb\RdwApi\Filament\Forms\Components\RdwApiLicenseplate;
...
RdwApiLicenseplate::make('licenseplate')
->label(__('rdw-api::form.licenseplateLabel'))
->default('155GV3')
->licenseplateStyle() // Basic style Dutch licenseplate
- Request to the active API (default: opendata.rdw.nl) \
- All RDW endpoints are selected
use Jdkweb\RdwApi\Enums\Endpoints;
use Jdkweb\RdwApi\Enums\OutputFormat;
use Jdkweb\RdwApi\Filament\Forms\Components\RdwApiLicenseplate;
...
RdwApiLicenseplate::make('licenseplate')
->label(__('rdw-api::form.licenseplateLabel'))
->default('155GV3')
->setApi(1)
->setEndpoints(Endpoints::cases())
->setOutputformat(OutputFormat::ARRAY)
->setLanguage('en')
->licenseplateStyle()
->setApi(int|string|\Closure) // 0 | opendata | 1 | overheid
Overwrite the config settings
- 0 or 'opendata' for using the RDW API opendata.rdw.nl [default]
- 1 or 'overheidio' for using the overheid.io API
use \Jdkweb\RdwApi\Enums\Endpoints;
...
->setEndpoints(string|array|Endpoints|\Closure)
#examples
# one string
->setEndpoints('vehicle')
# array with strings
->setEndpoints([
'vehicle',
'fuel'
])
# array with endpoints
->setEndpoints([
Endpoints::VEHICLE,
Endpoints::FUEL,
])
# closure
->setEndpoints(fn() => ($when ? Endpoints::cases() : Endpoints::BODYWORK))
# select all
->setEndpoints(Endpoints::cases())
Available endpoints (not case sensitive):
- Endpoints::VEHICLE | vehicle
- Endpoints::VEHICLE_CLASS |vehicle_class
- Endpoints::FUEL | fuel
- Endpoints::BODYWORK | bodywork
- Endpoints::BODYWORK_SPECIFIC | bodywork_specific
- Endpoints::AXLES | axles
- Endpoints::cases() [default]
->outputFormat(string|OutputFormat|\Closure)
#examples
->outputFormat('array')
->outputFormat(OutputFormat::ARRAY)
->setOutputformat(fn(Forms\Get $get) => $get('output_format'))
- OutputFormat::ARRAY | array [default]
- OutputFormat::JSON | json
- OutputFormat::AML | xml
by using this method the response contains a formated output. see RdwApiResponse
->setLanguage(string|\Closure)
Force output language, so form can be English and RDW response in Dutch.
Available:
- nl
- en
->licenseplateStyle()
->licenseplateStyle('taxi') // blue taxi plate
RDW API request with to filament form data
public function handleForm(string $form): void
{
$result = RdwApiRequest::make()
->setFormData($this->form)
->fetch();
Response data form the RDW API request in $result:
Jdkweb\RdwApi\Controllers\RdwApiResponse {#2800 ▼
+response: array:2 [▶] // API response
+request: {#3036 ▶} // Request vars
+output: array:2 [▶] // Formated output when setOutputFormat is used
+status: true
}
See rdw-api for the response methods
Create Filament form
use Jdkweb\RdwApi\Enums\Endpoints;
use Jdkweb\RdwApi\Enums\OutputFormat;
use Jdkweb\RdwApi\Controllers\RdwApiRequest;
use Jdkweb\RdwApi\Filament\Forms\Components\RdwApiLicenseplate;
use Jdkweb\RdwApi\Filament\Forms\Components\RdwApiResponse;
...
/**
* Dataset Selectbox
*/
Forms\Components\Select::make('datasets')
->label(__('rdw-api::form.selectdatasetLabel'))
->multiple()
->options(Endpoints::class)
->default([
Endpoints::VEHICLE,
Endpoints::FUEL
])
->hintAction(selectAllDatasets()) // Helper function for select all link
->reactive() // Enables reactivity
->required(),
//-----------------------------------------------------------------------------
/**
* Licenseplate
*
* Extra reactive data for Endpoints and outputFormat
*/
RdwApiLicenseplate::make('licenseplate')
->label(__('rdw-api::form.licenseplateLabel'))
->setOutputformat(fn(Forms\Get $get) => $get('output_format'))
->setEndpoints(fn(Forms\Get $get) => $get('datasets'))
->required()
->licenseplateStyle()
->live(true)
->afterStateUpdated(function ($state, Forms\Set $set) use ($form) {
$result = \Jdkweb\RdwApi\Controllers\RdwApiRequest::make()
->setFormData($form)
->fetch();
if ($result->status === false) {
return;
}
// Handle data
// $set('merk', $result->quickSearch('merk'));
// $set('voertuigsoort', $result->quickSearch('voertuigsoort'));
// $set('brandstof_omschrijving', $result->quickSearch('1.brandstof_omschrijving')); // type or hybrid: first type
// $set('aslast', $result->quickSearch('2.wettelijk_toegestane_maximum_aslast')); // second axle
// ...
}),
//-----------------------------------------------------------------------------
/**
* Selectbox for the output format
*/
Forms\Components\Select::make('output_format')
->label(__('rdw-api::form.formatLabel'))
->required()
->default(OutputFormat::XML)
->options(OutputFormat::class)
->reactive() // Enables reactivity
Handle Form data
...
public function handleForm(string $form): void
{
// Get RDW data
$result = RdwApiRequest::make()
->setFormData($this->form)
->fetch();
...
..
// Handle data format
switch ($data->request->outputformat) {
case OutputFormat::XML:
$data->toXml(true)
...
There is a demo available to test this wrapper
Two options to use the demo:
-
Add this value to .env
RDW_API_DEMO=1
-
Import the rwd-api config en set the value to 1 (Installation)
Demo: 0 = Off | 1 = On
rdw_api_demo => 1,
http://[domainname]/rdw-api/demo