kikter / states-and-local-govt
Populates your DB with all the states in Nigeria and their local governments. It also creates the models for you
dev-main
2022-06-18 16:50 UTC
Requires
- php: ^7.2|^8.0
- illuminate/support: ^6.9|^7.0|^8.0|^9.0
This package is auto-updated.
Last update: 2024-10-18 21:59:47 UTC
README
A Laravel Package that populates your database with all the states in the Nigeria and their corresponding local governments.
Setup
- Include package in your project by running
composer require bodunde/states-and-local-govt
- Add
Bodunde\SLG\SLGServiceProvider::class
to provider inapp.php
underconfig
directory - Publish package resources by running
php artisan vendor:publish
. Running this command would publish models, migrations and seeders. - Run published migrations
php artisan migrate
- Regenerate your autoload files
composer dump-autoload
- Run published database seeders
php artisan db:seed --class=SlgTableSeeder
Usage
- Import models into your controllers
Note: If your root namespace in your application isn't app
make sure you go to the models and modify the namespace
... use App\State; use App\LocalGovt; ... ... // fetch all states $states = State::all(); // fetch state by id $state = State::find($id) // where $id = 1 // fetch state by name $state = State::findByName("Lagos State"); //get state local governments $lg = $state->localGovernments; // get all local governments $lgs = LocalGovt::all(); // fetch local government by id $lg = LocalGovt::find($id) // where $id = 1 // fetch local government state $state = $lg->state;