Updat Seeder, add village seeder
This commit is contained in:
parent
6dd27e5f28
commit
344502e9f3
@ -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();
|
||||
|
@ -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'],
|
||||
]);
|
||||
|
@ -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,
|
||||
]);
|
||||
}
|
||||
|
||||
|
44
Database/Seeders/VillageSeeder.php
Normal file
44
Database/Seeders/VillageSeeder.php
Normal 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
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
Loading…
Reference in New Issue
Block a user