Laravel package for retreiving Ghana's regions and districts
PHP 5.4+ and Composer are required.
To get the latest version of this package add the following block of code to the require block of your project's composer.json
"wapnen/GHRegionsDistrict": "1.0.*"
You'll then need to run composer install
or composer update
to download it and have the autoloader updated.
Once GhRegionsDistrict is installed, you need to register the service provider. Open up config/app.php
and add the following to the providers
key.
Wapnen\GhRegionDistrict\GhRegionDistrictServiceProvider::class,
To start using this package, you'll need to publish all vendor assets:
$ php artisan vendor:publish --provider="Wapnen\GhRegionDistrict\GhRegionDistrictServiceProvider"
Now migrate your database to include the regions and districts tables
$ php artisan migrate
Add the following to your application's Databaseseeder.php file
$this->call(RegionTableSeeder::class);
$this->call(District1TableSeeder::class);
$this->call(District2TableSeeder::class);
$this->call(District3TableSeeder::class);
$this->call(District4TableSeeder::class);
$this->call(District5TableSeeder::class);
$this->call(District6TableSeeder::class);
$this->call(District7TableSeeder::class);
$this->call(District8TableSeeder::class);
$this->call(District9TableSeeder::class);
$this->call(District10TableSeeder::class);
run the following command to Autoload your files
composer dump-autoload
Finally run the following command to seed to your database
$ php artisan db:seed
To retrieve all the regions
$regions = DB::table('regions')->get();
To retrieve one region
$region = DB::table('regions')->where('name', 'Ashanti)->first();
To get all the districts for a particular region
$region = DB::table('regions')->where('name', 'Ashanti)->first();
$districts = DB::table('districts)->where('region_id' , $region->id)->get();
Please feel free to fork this package and contribute by submitting a pull request to enhance the functionalities.
You can follow me on twitter!
The MIT License (MIT).