open($file_path); $cell_map = [ // Urutan kolom di excel 'No', 'Nama KOP', 'Nama KLY', 'Kode Provider', 'Nama Provider', 'Jalan', 'KODEPOS', 'OPERASIONAL DAY', 'OPERASIONAL HOUR', 'AVAILABLE Brozo', 'Geo Tag' ]; foreach ($reader->getSheetIterator() as $sheet) { foreach ($sheet->getRowIterator() as $index => $row) { if ($index >= 4) { $cells = $row->getCells(); $data = [ 'code' => $cells[3]->getValue(), 'name' => $cells[4]->getValue(), 'type' => 'hospital', 'corporate_id_partner' => 5, // Mandiri Inhealth 'phone' => $cells[11]->getValue(), 'email' => isset($cells[12]) ? $cells[12]->getValue() : null, ]; // Update or create organization $organization = Organization::updateOrCreate( ['code' => $cells[3]->getValue()], $data ); // Update or create address $geo = str_replace("'", "", $cells[9]->getValue()); // Hilangkan tanda petik tunggal $datageo = explode(",", $geo); // Pastikan $datageo memiliki dua elemen sebelum mencoba mengaksesnya $lat = isset($datageo[0]) ? $datageo[0] : null; $lng = isset($datageo[1]) ? $datageo[1] : null; $address = $organization->addresses()->updateOrCreate( ['addressable_id' => $organization->id], [ 'use' => 'both', 'type' => 'physical', 'text' => $cells[5]->getValue(), 'postal_code' => $cells[6]->getValue(), 'lat' => $lat, 'lng' => $lng, ] ); // Set main address id $organization->main_address_id = $address->id; $organization->save(); } } } $reader->close(); } }