Updat Seeder, add village seeder

This commit is contained in:
daeng.deni@dharma.or.id 2023-06-08 09:04:12 +07:00
parent 6dd27e5f28
commit 344502e9f3
6 changed files with 584327 additions and 8 deletions

View File

@ -19,6 +19,7 @@ use Illuminate\Database\Migrations\Migration;
$table->foreignIdFor(District::class)->constrained()->onDelete('cascade');
$table->string('code', 15);
$table->string('name');
$table->string('postal_code',5)->nullable()->comment('Kode Pos');
$table->string('status', 1)->default('1');
$table->timestamps();
$table->softDeletes();

View File

@ -19,7 +19,7 @@
foreach ($data as $value) {
District::create([
'city_id' => $this->getCity($value['city']),
'city_id' => $this->getCityId($value['city']),
'code' => $value['code'],
'name' => $value['name'],
]);

View File

@ -21,8 +21,9 @@
$data = $this->data();
foreach ($data as $value) {
$permission = Permission::create([
'name' => $value['name'],
$permission = Permission::updateOrCreate([
'name' => $value['name']
], [
'permission_group_id' => $value['group'],
]);
@ -42,6 +43,8 @@
CountrySeeder::class,
ProvinceSeeder::class,
CitySeeder::class,
DistrictSeeder::class,
VillageSeeder::class,
]);
}

View File

@ -0,0 +1,44 @@
<?php
namespace Modules\Master\Database\Seeders;
use Illuminate\Database\Seeder;
use Modules\Master\Entities\District;
use Modules\Master\Entities\SubDistrict;
class VillageSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$data = $this->data();
foreach ($data as $value) {
SubDistrict::create([
'district_id' => $this->getDistrictId($value['district']),
'code' => $value['code'],
'name' => $value['name'],
'postal_code' => $value['postal_code'],
]);
}
}
public function data()
{
$villages = file_get_contents(dirname(__FILE__, 1) . '/village.json');
return json_decode($villages, true);
}
function getDistrictId($areacode)
{
$province = District::where('code', $areacode)->first();
return $province->id;
}
}

500804
Database/Seeders/village.json Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff