enflow / laravel-address
支持多驱动器的地址自动完成
Requires
- php: ^8.2
- guzzlehttp/guzzle: ^7.1
- illuminate/http: ^10.0|^11.0
- illuminate/support: ^10.0|^11.0
- symfony/intl: ^7.0
Requires (Dev)
- laravel/pint: ^1.0
- orchestra/testbench: ^8.0|^9.0
- phpunit/phpunit: ^10.5|^11.0
- spatie/phpunit-snapshot-assertions: ^5.0
This package is auto-updated.
Last update: 2024-09-08 03:42:12 UTC
README
《enflow/laravel-address》包提供了一种实现带有自动完成功能的地址字段的建议方式。
用法
步骤 1 - 安装包
您可以通过composer安装此包
composer require enflow/laravel-address
步骤 2 - 配置
您必须发布配置文件以设置您要使用的驱动程序。
推送配置文件
php artisan vendor:publish --provider="Enflow\Address\AddressServiceProvider" --tag="config"
您必须指定您的驱动程序选择。我们提供了一个内置的HERE驱动程序。请参阅“驱动程序”部分了解如何获取API密钥。
步骤 3 - 迁移
推送迁移文件
php artisan vendor:publish --provider="Enflow\Address\AddressServiceProvider" --tag="migrations"
步骤 4 - 准备您的模型
提供的《Address》模型可免费使用,并且您可以像配置常规Eloquent关系一样配置它
迁移
Schema::table('companies', function (Blueprint $table) { // ... $table->foreignId('address_id')->constrained(); });
模型
<?php use Enflow\Address\Models\Address; use Illuminate\Database\Eloquent\Model; class Company extends Model { public function address() { return $this->belongsTo(Address::class); } }
步骤 5 - 前端
我们强烈建议使用我们的@enflow/laravel-address-ui前端包。此包添加了将自动完成选项添加到地址输入的功能,以便最终用户可以轻松选择他们的地址。
有关安装说明,请参阅https://github.com/enflow-nl/laravel-address-ui
步骤 6 - 持久化
在表单提交后,我们希望将地址信息连接到模型。这可以通过Address::persist方法完成。您可以使用它
$model->address()->associate(Address::persist($request->get('address')));
驱动程序
我们提供以下内置驱动程序。这可能会在未来扩展,我们欢迎为新的驱动程序提交PR。
HERE
HERE Geocoding and Search提供了一个快速且易于使用的自动建议选项。我们推荐此选项,因为它具有相对较低的成本和易于使用,无需额外的法律条款。
产品页面:https://developer.here.com/products/geocoding-and-search
定价:https://developer.here.com/pricing
您可以通过注册账户获取API令牌。
Google Places
Google Places目前不支持,这是我们希望在将来支持的功能。欢迎提交PR!
Mapbox
Mapbox目前不支持,这是我们希望在将来支持的功能。欢迎提交PR!
测试
$ composer test
贡献
请参阅CONTRIBUTING以获取详细信息。
安全
如果您发现任何安全相关的问题,请通过电子邮件michel@enflow.nl而不是使用问题跟踪器。
鸣谢
关于Enflow
Enflow是一家位于荷兰阿尔芬的数字创意代理商。我们专注于开发网络应用程序、移动应用程序和网站。您可以在我们的网站上找到更多信息https://enflow.nl/en。
许可
MIT许可证(MIT)。有关更多信息,请参阅许可文件。