定制 jdkweb/rdw-api-filament 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jdkweb/rdw-api-filament

最新稳定版本:v1.2.2

Composer 安装命令:

composer require jdkweb/rdw-api-filament

包简介

Filament extension for rdw-api. rdw-api is a wrapper for RDW API

README 文档

README

Packagist Version Static Badge Static Badge Static Badge Packagist Dependency Version

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.

Depends on: Static Badge Static Badge

This package extends jdkweb/rdw-api to be used in Filament.

Table of contents

Installation

Requires PHP 8.1 and Laravel 10 and Filament 3.0 or higher
Install the package via composer:

composer require jdkweb/rdw-api-filament

Translation

Translations available:

See: Static Badge Static Badge

Usage

Form Field

Basic usage

filament setup

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

All options used

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

Options

Select other API than default

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

Select endpoints for request

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]

Format of the response output

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

Set output language

->setLanguage(string|\Closure)

Force output language, so form can be English and RDW response in Dutch.
Available:

  • nl
  • en

Basic style for Dutch licenseplate

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

Handle RDW response

RDW API request with to filament form data

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

RDW Response

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

Example

filament setup

Create Filament form

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
    ->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(OutputFormats::XML)
    ->options(OutputFormats::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)
    ...

Demo

There is a demo available to test this wrapper
Two options to use the demo:

  1. .env

     RDW_API_DEMO=1
    Add this value to .env
  2. config

    Import the rwd-api config en set the value to 1 (Installation)
     rdw_api_demo => 1,
    Demo: 0 = Off | 1 = On

Demo url

http://[domainname]/rdw-api/demo 

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2025-03-27