raphyabak/state-lga

将所有尼日利亚的州和其地方政府填充到您的数据库中。它还会为您创建模型。

dev-main 2022-03-28 18:51 UTC

This package is not auto-updated.

Last update: 2024-09-25 05:10:50 UTC


README

一个Laravel包,它将所有尼日利亚的州和对应的地方政府填充到您的数据库中。

设置

  • 通过运行 composer require bodunde/states-and-local-govt 将包包含到您的项目中。
  • Bodunde\SLG\SLGServiceProvider::class 添加到位于 config 目录下的 app.php 文件中的 providers。
  • 通过运行 php artisan vendor:publish 发布包资源。运行此命令将发布模型、迁移和种子文件。
  • 运行发布的迁移 php artisan migrate
  • 重新生成您的autoload文件 composer dump-autoload
  • 运行发布的数据库种子文件 php artisan db:seed --class=SlgTableSeeder

用法

  • 将模型导入到您的控制器中

注意:如果您应用程序的根命名空间不是 app,请确保您进入模型并修改命名空间

...
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;