kraenzle-ritter/resources-components

v0.2.8 2023-03-24 08:16 UTC

This package is auto-updated.

Last update: 2024-09-26 13:55:53 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License

在权威数据库中搜索实体并将它们与本地数据关联。

  • Anton
  • Geonames
  • GND
  • Idiotikon
  • Metagrid
  • ortsnamen.ch
  • Wikidata
  • 维基百科

安装

通过 Composer

$ composer require kraenzle-ritter/resources-component

要使用此包,还需要安装 kraenzle-ritter/resources

在您的视图中,您可以像这样使用该包

@livewire('resources-list', [$model, 'deleteButton' => true])
@livewire('provider-select', [$model, $providers', 'actors'])

$model 是应成为可资源化的模型。

$providers 是实际使用的资源提供者列表(数组)。您可以通过控制器或配置文件传递它们。实际可用的包括任何 Anton 安装(见下文)、geonames、gnd、metagrid、维基百科、wikidata。

对于 provider-select 的最后一个参数是端点,即实体。您只需要在此时使用 Anton 作为提供者。

组件在保存资源时触发一个事件(ResourceSaved)。因此,您可以在您的应用程序中定义和注册一个监听器。

<?php

namespace App\Listeners;

use KraenzleRitter\ResourcesComponents\Events\ResourceSaved;

class UpdateLocationWithGeonamesCoordinates
{

    public function handle(ResourceSaved $event)
    {
        if ($this->resource->provider == 'geonames') {
            \Log::debug($event->resource);
            \Log::debug($event->model);
        }

    }
}

在您的 EventServiceProvider 中

<?php
namespace App\Providers;

use Illuminate\Support\Facades\Event;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use KraenzleRitter\ResourcesComponents\Events\ResourceSaved;
use App\Listeners\UpdateLocationWithGeonamesCoordinates;

class EventServiceProvider extends ServiceProvider
{

    /**
     * The event listener mappings for the application.
     *
     * @var array
     */
    protected $listen = [
        ResourceSaved::class => [
            UpdateLocationWithGeonamesCoordinates::class
        ]
    ];

环境变量

对于某些提供者,您需要在您的 .env 文件中设置一些变量。

ANTON_PROVIDER_SLUG=kr
ANTON_URL=https://kr.anton.ch
ANTON_API_URL=http://kkr.anton.test/api
ANTON_API_TOKEN=secret

GEONAMES_USERNAME=demo

模型

模型应具有 resources_search 属性或 name 属性。

用法

只需将组件放入您的视图中

@livewire('gnd-lw-component', ['params' => ['queryOptions' => ['size' => 5]]])

许可

MIT。有关更多信息,请参阅 许可文件