enflow / laravel-address
Address autocomplete with support for multiple drivers
Fund package maintenance!
enflow.nl/contact
Installs: 3 517
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 3
Forks: 2
Open Issues: 1
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-11-08 04:00:25 UTC
README
The enflow/laravel-address
package provides a opinionated way on how to implement address fields with autocomplete.
Usage
Step 1 - Install the package
You can install the package via composer:
composer require enflow/laravel-address
Step 2 - Config
You must publish the config to set the driver you which to use.
Pushing the config file:
php artisan vendor:publish --provider="Enflow\Address\AddressServiceProvider" --tag="config"
You must specify your driver choice. We provide a driver for HERE out of the box. See the 'Driver' section how to obtain a API key.
Step 3 - Migration
Pushing the migration file:
php artisan vendor:publish --provider="Enflow\Address\AddressServiceProvider" --tag="migrations"
Step 4 - Prepare your model
The Address
model is provided free to use, and you are able to configure it just like a normal Eloquent relationship:
Migration
Schema::table('companies', function (Blueprint $table) { // ... $table->foreignId('address_id')->constrained(); });
Model
<?php use Enflow\Address\Models\Address; use Illuminate\Database\Eloquent\Model; class Company extends Model { public function address() { return $this->belongsTo(Address::class); } }
Step 5 - Frontend
We highly recommend the use of our @enflow/laravel-address-ui
frontend package. This package adds the ability to add a autocomplete option to your address input for the end-user to easily select their address.
For installation instructions, see https://github.com/enflow-nl/laravel-address-ui
Step 6 - Persisting
After the form has been submitted, we wish to connect the address info the the model. This can be done with the Address::persist
method. You may use it like:
$model->address()->associate(Address::persist($request->get('address')));
Drivers
We support the following drivers out of the box. This may be extended in the future, and we welcome PRs for new drivers.
HERE
HERE Geocoding and Search provides a fast and easy to use autosuggestion option. We recomend this option due it's relative low cost and ease of use, without additional legal terms.
Product page: https://developer.here.com/products/geocoding-and-search
Pricing: https://developer.here.com/pricing
You may obtain a API token by registrating for an account.
Google Places
Google Places isn't support out of the box and is something we want to support in the future. PRs are welcome!
Mapbox
Mapbox isn't support out of the box and is something we want to support in the future. PRs are welcome!
Testing
$ composer test
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email michel@enflow.nl instead of using the issue tracker.
Credits
About Enflow
Enflow is a digital creative agency based in Alphen aan den Rijn, Netherlands. We specialize in developing web applications, mobile applications and websites. You can find more info on our website.
License
The MIT License (MIT). Please see License File for more information.