Why use Location-demographia laravel library

Emmanuel Paul Mnzava.
2 min readFeb 23, 2021

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

  1. Written in PHP and Works on laravel version 7.1 and above.
  2. Loads countries, cities, and states from https://www.printful.com/docs/countries automatically on running a command.
  3. Comes with migrations and models for ( Country, State, and City).
  4. 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

--

--

Emmanuel Paul Mnzava.
Emmanuel Paul Mnzava.

Written by Emmanuel Paul Mnzava.

Software Engineer and techprenuer with passion of helping entreprenuers and small businesses using Technology.

No responses yet