aboleon / metaframework-google-places
Google Places address autocomplete component for Laravel
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/aboleon/metaframework-google-places
Requires
- php: ^8.3
- aboleon/metaframework-inputable: ^1.0
- aboleon/metaframework-support: 0.*
- illuminate/contracts: ^11.0|^12.0
- illuminate/database: ^11.0|^12.0
- illuminate/support: ^11.0|^12.0
- illuminate/translation: ^11.0|^12.0
- illuminate/view: ^11.0|^12.0
Requires (Dev)
- laravel/pint: ^1.27
- orchestra/testbench: ^9.0|^10.0
- phpunit/phpunit: ^11.0
README
Google Places address autocomplete component for Laravel
Requirements
- PHP ^8.3
- Laravel ^11.0 | ^12.0
- MetaFramework Inputable
Installation
composer require aboleon/metaframework-google-places
Publish assets/config/translations:
php artisan vendor:publish --tag=mfw-google-places-config php artisan vendor:publish --tag=mfw-google-places-translations php artisan vendor:publish --tag=mfw-google-places-assets
Configuration
config/mfw-google-places.php:
return [ 'google' => [ 'places_api_key' => env('MFW_GOOGLE_PLACES_KEY', ''), ], 'countries_resolver' => null, ];
Resolver usage:
- Set
countries_resolverto a class that implementsgetCountryNameByCode($code)(and optional locale-awaregetCountryNameByCodeAndLocale). - Example:
MetaFramework\GooglePlaces\Accessors\Country::classto resolve country names from ISO-2 codes and locale files.
Usage
<x-mfw-google-places::form :model="$address" field="address" label="Address" :params="['required' => ['route', 'postal_code', 'locality']]" :hidden="['administrative_area_level_2']" :showCoords="true" />
To fully customize, publish the component and use the native Blade tag:
<x-google-places />
Artisan Commands
php artisan mfw-google-places:make-geo-model
php artisan mfw-google-places:make-geo-for-model {model?}
php artisan mfw-google-places:publish-component [--force]
php artisan mfw-google-places:publish-request [--force]
mfw-google-places:make-geo-modelgenerates a new Geo model and migration with all Google Places fields.mfw-google-places:make-geo-for-modeladds a Google Places Geo relation and migration to an existing model (optionally provide the model class).mfw-google-places:publish-componentpublishesapp/View/Components/GooglePlaces.phpandresources/views/components/google-places.blade.phpfor customization (use--forceto overwrite).mfw-google-places:publish-requestpublishes aGooglePlacesRequesttoapp/Http/Requestsfor customization (use--forceto overwrite).
Validation example:
use MetaFramework\GooglePlaces\Validation\GoogleAddressValidation; $rules = (new GoogleAddressValidation()) ->setPrefix('address') ->setRequiredFields(['route', 'postal_code', 'locality']) ->rules();
Customize the published request:
php artisan mfw-google-places:publish-request
// app/Http/Requests/GooglePlacesRequest.php public function rules(): array { return (new GoogleAddressValidation()) ->setPrefix('address') ->setRequiredFields(['route', 'postal_code', 'locality']) ->rules(); }