This commit is contained in:
R
2022-09-17 00:51:02 +07:00
parent 300b53942d
commit a9f29cd19d
28 changed files with 1122 additions and 13 deletions

View File

@@ -0,0 +1,65 @@
<?php
namespace Database\Seeders;
use App\Models\Organization;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Http;
class OrganizationSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$response = Http::get('http://localhost:8001/temp/organizations');
foreach ($response->json()['organizations'] as $organization) {
$newOrganization = Organization::updateOrCreate([
'code' => 'ORG000'.$organization['code'],
],[
'code' => 'ORG000'.$organization['code'],
'name' => $organization['name'],
'type' => 'hospital',
]);
$newAddress = $newOrganization->addresses()->updateOrCreate([
'id' => $newOrganization->main_address_id
],[
'use' => 'both',
'type' => 'physical',
'text' => $organization['address'],
'lat' => $organization['lat'],
'lng' => $organization['lng'],
]);
$newOrganization->main_address_id = $newAddress->id;
$newOrganization->save();
$newOrganization->metas()->updateOrCreate([
'type' => 'KodeRS',
], [
'system' => 'primaya-his',
'type' => 'KodeRS',
'value' => $organization['code']
]);
$newOrganization->metas()->updateOrCreate([
'type' => 'phone',
],[
'system' => 'default',
'type' => 'phone',
'value' => $organization['phone']
]);
$newOrganization->metas()->updateOrCreate([
'type' => 'timezone',
],['system' => 'default',
'type' => 'timezone',
'value' => $organization['timezone']
]);
}
}
}