marshmallow/address-prefiller

此包将根据邮政编码和门牌号码获取完整的地址信息。目前支持在线荷兰地址。


README

alt text

Nova 可翻译

Version Downloads Issues Licence

此包将根据提供的邮政编码和门牌号码自动填写地址字段。目前仅支持荷兰地址。可用于自定义应用程序或与 Laravel Nova 一起使用。

安装

通过 Composer 安装包

通过 Composer 在 Laravel 项目中安装此包。

# Install the package
composer require marshmallow/address-prefiller

Nova 中的使用

有一个自定义 Laravel Nova 字段可供使用。这非常类似于 Laravel Place 字段。不同之处在于,此字段不会与 Algolia 通信,而是与荷兰政府提供的官方公开 API 通信,其中应包含所有最新信息。

public function fields(Request $request)
{
    return [
        ID::make()->sortable(),
        $this->addressFields(),
    ];
}

protected function addressFields()
{
    return $this->merge([
        Zipcode::make(__('Zipcode prefiller'), __('Zipcode'), __('Housenumber'))
            /**
             * Let the package know which columns are connected to
             * the fields. The default values are commented after each
             * function call. Is your column names match these defaults,
             * you don't need to call all these functions.
             */
            ->zipcode('zipcode')
            ->housenumber('address_2')
            ->street('address_1')
            ->city('city')
            ->province('province')
            ->country('country')
            ->latitude('latitude')
            ->longitude('longitude'),

        /**
         * The field below will all be prefilled with the collected
         * data if we find a match on the submitted zipcode and housenumber.
         */
        Hidden::make(__('Zipcode'), 'zipcode')->hideFromIndex(),
        Hidden::make(__('Housenumber'), 'address_2')->hideFromIndex(),
        Text::make(__('Street'), 'address_1')->hideFromIndex(),
        Text::make(__('City'), 'city')->hideFromIndex(),
        Text::make(__('Province'), 'province')->hideFromIndex(),
        Country::make(__('Country'), 'country')->hideFromIndex(),
        Text::make(__('Latitude'), 'latitude')->hideFromIndex(),
        Text::make(__('Longitude'), 'longitude')->hideFromIndex(),
    ]);
}

手动使用

我们提供了一个示例,说明如何在您的应用程序中使用此功能。我们目前在 Nova 设置中使用此功能,如果您缺少任何内容,请告诉我们!

use Marshmallow\Zipcode\Facades\Zipcode;

return Zipcode::get(
    $request->zipcode,
    $request->housenumber
);

测试

composer test

安全

如果您发现任何安全问题,请通过电子邮件 stef@marshmallow.dev 反馈,而不是使用问题跟踪器。

鸣谢

许可证

MIT 许可证 (MIT)。请参阅许可证文件获取更多信息。