join("subcontractors", "work_permit_documents.company", "subcontractors.company_name_ru") ->where("zone", "like", "%{$weldLog?->project}%") ->where("assigned_documents", "like", "%{$documentInfo->slug}%") ->get(); // Iterate over each sheet in the spreadsheet foreach ($spreadsheet->getAllSheets() as $sheet) { // Loop through all the cells in the sheet and replace placeholders foreach ($sheet->getRowIterator() as $row) { foreach ($row->getCellIterator() as $cell) { $cellValue = $cell->getValue(); if (is_string($cellValue)) { // Perform the replacement for each work permit user foreach ($workPermitUsers as $wpi) { $replacements = [ "{".$wpi->company_code.$wpi->sign_order."_name_surname}" => $wpi->name_surname, "{".$wpi->company_code.$wpi->sign_order."_company_name}" => $wpi->company, "{".$wpi->company_code.$wpi->sign_order."_certificate_no}" => $wpi->certificates_number, "{".$wpi->company_code.$wpi->sign_order."_certificate_number}" => $wpi->certificates_number, "{".$wpi->company_code.$wpi->sign_order."_address_ru}" => $wpi->address_ru, "{".$wpi->company_code.$wpi->sign_order."_project_city_ru}" => $wpi->project_city_ru, "{".$wpi->company_code.$wpi->sign_order."_duty}" => $wpi->duty, "{".$wpi->company_code.$wpi->sign_order."_tax}" => $wpi->tax, "{".$wpi->company_code.$wpi->sign_order."_tax2}" => $wpi->tax2, "{".$wpi->company_code.$wpi->sign_order."_address_ru2}" => $wpi->address_ru2, "{".$wpi->company_code.$wpi->sign_order."_document_number}" => $wpi->document_number, "{".$wpi->company_code.$wpi->sign_order."_attorney}" => $wpi->attorney, "{".$wpi->company_code.$wpi->sign_order."_attorney_date}" => df($wpi->attorney_date), ]; // Replace each placeholder in the cell value foreach ($replacements as $placeholder => $replacement) { if (strpos($cellValue, $placeholder) !== false) { $cellValue = str_replace($placeholder, $replacement, $cellValue); } } // Update the cell with the new value $cell->setValue($cellValue); } } } } } // Return the modified spreadsheet return $spreadsheet; } ?>