Server 103 Commit
This commit is contained in:
56
database/seeders/HealthcareSeeder.php
Normal file
56
database/seeders/HealthcareSeeder.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Models\Organization;
|
||||
use App\Models\OLDLMS\Healthcare;
|
||||
use Exception;
|
||||
|
||||
class HealthcareSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$datas = Organization::with('addresses')
|
||||
->where('type', 'hospital')
|
||||
->whereNotNull('corporate_id_partner')
|
||||
->get();
|
||||
|
||||
foreach ($datas as $data) {
|
||||
// Fetch related healthcare record
|
||||
$healthCare = Healthcare::where('sHealthcare', 'like', '%' . $data->name . '%')->first();
|
||||
$healthCareData = [
|
||||
'sHealthCare' => $data->name,
|
||||
'sAlamat' => $data->addresses->first()->text ?? null, // Assuming addresses is a collection
|
||||
'nIDCountry' => 1,
|
||||
'sStatus' => 1,
|
||||
];
|
||||
|
||||
try {
|
||||
if ($healthCare) {
|
||||
// Update healthcare record
|
||||
$healthCare->update($healthCareData);
|
||||
} else {
|
||||
// Insert healthcare record
|
||||
$healthCareData = [
|
||||
'sHealthCare' => $data->name,
|
||||
'sAlamat' => $data->addresses->first()->text ?? null, // Assuming addresses is a collection
|
||||
'nIDCountry' => 1,
|
||||
'sStatus' => 1,
|
||||
'nIDHealthCareCategory' => 1
|
||||
];
|
||||
Healthcare::create($healthCareData);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
dd($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user