Why use Location-demographia laravel library
Most of the time when developers such as myself create a system we usually meet this scenario where on sign up or registration, We tend to have a need to ask the user to select a Country, State, and or City. Coding this on every project from scratch can be tiresome and time-wasting.Location-demographia library package comes in to solve such a problem, It's carefully crafted to give you all countries in the world with their respective cities and states.
Let's go over it below
- Written in PHP and Works on laravel version 7.1 and above.
- Loads countries, cities, and states from https://www.printful.com/docs/countries automatically on running a command.
- Comes with migrations and models for ( Country, State, and City).
- Comes with various queries.
Installation
You can install the package via composer:
composer require epmnzava/location-demografia
Update your config (for Laravel 5.4 and below)
Add the service provider to the provider's array in config/app.php:
"Epmnzava\LocationDemografia\LocationDemografiaServiceProvider"::class
Add the facade to the aliases array in config/app.php:
'Location'=>Epmnzava\LocationDemografia\LocationDemografiaFacade,
After you have added the above classes on config/app.php
run the below command to publish config, run migrations, and load data thus ( countries and their states).
php artisan locationdemografia:install
If you have the necessary tables already on your database, you can easily run the following command to only load the necessary location data.
php artisan locationdemografia:install --loadonly
Usage
<?phpuse Epmnzava\LocationDemografia;class TestController extends Controller{
public function test(){$location= new LocationDemografia;//get all countries
$countries=$location->getCountries();//get all countries states$states=$location->getCountriesState($countryid);}}
Before you go… Thanks for reading the article! If you enjoyed it, please don’t forget to show your appreciation by clicking 👏 below!
Any questions or comments hit me up on
Mail: epmnzava@gmail.com
Twitter: https://twitter.com/epmnzava
Github: https://github.com/dbrax