PHP code example of jdkweb / rdw-api-filament

1. Go to this page and download the library: Download jdkweb/rdw-api-filament 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/ */

    

jdkweb / rdw-api-filament example snippets


use Jdkweb\RdwApi\Filament\Forms\Components\RdwApiLicenseplate;
...
RdwApiLicenseplate::make('licenseplate')
    ->label(__('rdw-api::form.licenseplateLabel'))
    ->default('155GV3')    
    ->licenseplateStyle()  // Basic style Dutch licenseplate

use Jdkweb\RdwApi\Filament\Enums\Endpoints;
use Jdkweb\RdwApi\Filament\Enums\OutputFormats;
use Jdkweb\RdwApi\Filament\Forms\Components\RdwApiLicenseplate;
...
RdwApiLicenseplate::make('licenseplate')
    ->label(__('rdw-api::form.licenseplateLabel'))
    ->default('155GV3')    
    ->setApi(1)
    ->setEndpoints(Endpoints::cases())    
    ->setOutputformat(OutputFormats::ARRAY)    
    ->setLanguage('en')
    ->licenseplateStyle() 

->setApi(int|string|\Closure) // 0 | opendata | 1 | overheid    

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())    
  
->outputFormat(string|OutputFormat|\Closure)

#examples  
    ->outputFormat('array')
    ->outputFormat(OutputFormat::ARRAY)
    ->setOutputformat(fn(Forms\Get $get) => $get('output_format'))

->setLanguage(string|\Closure)

->licenseplateStyle() 
->licenseplateStyle('taxi')  // blue taxi plate 

public function handleForm(string $form): void
{
    $result = RdwApiRequest::make()
        ->setFormData($this->form)
        ->fetch();

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
}

use Jdkweb\RdwApi\Filament\Enums\Endpoints;
use Jdkweb\RdwApi\Filament\Enums\OutputFormats;
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
    ->    ->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'))
    ->

...

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)
    ...


    RDW_API_DEMO=1
   

    rdw_api_demo => 1,