Import Templates, Preview, and Validation
Guide users toward clean data and report row-level problems before insertion.
Updated
domainImportTemplate()previewDomainImport()validateImport()duplicateRows()What you will learn
- Generate a validated spreadsheet template.
- Preview and confirm headers before importing.
- Return actionable row-level validation messages.
Generate a matching domain template#
MnbExcel::domainImportTemplate('products', [
'include_examples' => true,
'include_instructions' => true,
])
->save('product-import-template.xlsx');Preview the uploaded workbook#
$preview = MnbExcel::previewDomainImport('products', 'products.xlsx', [
'sheet' => 'Products',
'limit' => 25,
]);
print_r([
'headers' => $preview['headers'] ?? [],
'sample' => $preview['rows'] ?? [],
'warnings' => $preview['warnings'] ?? [],
]);Validate custom rows before SQL#
$validation = MnbExcel::validateArray($rows, [
'sku' => 'required|unique_in_file',
'name' => 'required',
'price' => 'required|numeric|min:0',
'email' => 'nullable|email',
]);
if (($validation['valid'] ?? false) !== true) {
print_r($validation['failed_rows'] ?? []);
}Make errors useful to the uploader#
- Include the physical row number.
- Name the source header and canonical field.
- Explain the invalid value without exposing secrets.
- Provide a downloadable failed-row workbook or CSV.
- Keep successful and failed counts visible in the final summary.
Was this guide useful?Use GitHub issues for corrections, missing examples, or unclear behavior.
Open an issue