Laravel package to get Ghana's regions and districts
Laravel package for retreiving Ghana's regions and districts, (*1)
PHP 5.4+ and Composer are required., (*2)
To get the latest version of this package add the following block of code to the require block of your project's composer.json, (*3)
"wapnen/GHRegionsDistrict": "1.0.*"
You'll then need to run composer install
or composer update
to download it and have the autoloader updated., (*4)
Once GhRegionsDistrict is installed, you need to register the service provider. Open up config/app.php
and add the following to the providers
key., (*5)
Wapnen\GhRegionDistrict\GhRegionDistrictServiceProvider::class,
To start using this package, you'll need to publish all vendor assets:, (*6)
$ php artisan vendor:publish --provider="Wapnen\GhRegionDistrict\GhRegionDistrictServiceProvider"
Now migrate your database to include the regions and districts tables, (*7)
$ php artisan migrate
Add the following to your application's Databaseseeder.php file, (*8)
$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, (*9)
composer dump-autoload
Finally run the following command to seed to your database, (*10)
$ php artisan db:seed
To retrieve all the regions, (*11)
$regions = DB::table('regions')->get();
To retrieve one region, (*12)
$region = DB::table('regions')->where('name', 'Ashanti)->first();
To get all the districts for a particular region, (*13)
$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., (*14)
You can follow me on twitter!, (*15)
The MIT License (MIT)., (*16)