marshmallow/address-prefiller 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

marshmallow/address-prefiller

Composer 安装命令:

composer require marshmallow/address-prefiller

包简介

This package will get the full address information based on the zipcode and house number. Currently online dutch addresses are supported.

README 文档

README

alt text

Laravel Address Prefiller

Latest Version on Packagist Tests Total Downloads Issues License

This package prefills address fields based on a provided zipcode and house number. It currently only supports Dutch addresses. You can use it in your custom applications, or use the ready-made field with Laravel Nova.

The address data is retrieved from the official open API provided by the Dutch government (PDOK Locatieserver), which should contain the latest information.

Installation

Install the package via Composer:

composer require marshmallow/address-prefiller

The service provider (Marshmallow\Zipcode\FieldServiceProvider) is auto-discovered by Laravel, so there is nothing else to register.

Usage in Nova

A custom Laravel Nova field is available which you can use. It works very similarly to the Laravel Place field. The difference is that this field does not talk to Algolia, but to the official open API provided by the Dutch government, which should contain the latest information.

use Marshmallow\Zipcode\Nova\Zipcode;

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. If your column names match these defaults,
             * you don't need to call all these functions.
             */
            ->zipcode('zipcode')         // default: zipcode
            ->housenumber('housenumber') // default: housenumber
            ->street('street')           // default: street
            ->city('city')               // default: city
            ->province('province')       // default: province
            ->country('country')         // default: country
            ->latitude('latitude')       // default: latitude
            ->longitude('longitude'),    // default: longitude

        /**
         * The fields below will all be prefilled with the collected
         * data if we find a match on the submitted zipcode and house number.
         */
        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(),
    ]);
}

The field exposes a fluent setter for each address attribute so you can map it to the column names used in your resource: zipcode(), housenumber(), street(), city(), province(), country(), latitude() and longitude().

Usage manually

We have provided an example of how you can use this functionality in your own application. We've currently only used this in the Nova setting, so if you're missing anything, please let us know!

use Marshmallow\Zipcode\Facades\Zipcode;

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

You can map the returned address fields to your own keys by chaining the setter methods before calling get():

use Marshmallow\Zipcode\Facades\Zipcode;

return Zipcode::street('address_1')
    ->city('city')
    ->province('province')
    ->country('country')
    ->latitude('latitude')
    ->longitude('longitude')
    ->get($request->zipcode, $request->housenumber);

Testing

composer test

Security Vulnerabilities

If you discover any security related issues, please email stef@marshmallow.dev instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see the License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-09-03

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固