public function export(Request $request)
{
try {
$query= MyModel::where('uuid', $request->uuid)->with('locations')->first();
//format name
$name = $query->name;
$name = strtolower($name); //According to the message returned by the catch it indicates that it is in this line where it fails
$name = str_replace(' ', '-', $name);
$name = preg_replace('/[^A-Za-z0-9\-]/', '', $name);
$fileName = 'File-'. $name .'-'.date('YmdHisv').'.xlsx';
$xlsFileTemp = storage_path(config('opi.app.local_temp_folder').$fileName);
$spreadsheet = new Spreadsheet;
$spreadsheet->setActiveSheetIndex(0);
$sheet = $spreadsheet->getActiveSheet();
$sheet->setTitle('Coverages');
$sheet->getStyle("A1:K200")->applyFromArray($this->borderResults);
$sheet->getStyle("E1:E100")->getAlignment()->setHorizontal('right');
$sheet->getStyle("I1:I100")->getAlignment()->setHorizontal('right');
$row = 3;
// Coverages section
$row = $this->general_information($sheet, $row, $iquote);
// set size cells for results
$cellSizeArray = ['C', 'D', 'E', 'F', 'G', 'H', 'I'];
foreach ($cellSizeArray as $key => $cell) {
$sheet->getColumnDimension($cell)->setWidth(18);
}
$cellSizeArray = ['C', 'D', 'E', 'F', 'G', 'H', 'I'];
foreach ($cellSizeArray as $key => $cell) {
$sheet->getColumnDimension($cell)->setWidth(18);
}
//back to the first sheet
$spreadsheet->setActiveSheetIndex(0);
$writer = new Xlsx($spreadsheet);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename='.$fileName);
header('Content-Description: '.$fileName);
$writer->save('php://output');
}
catch (\Exception $e) {
Log::error('- [Report] error in export excel '.$e->getMessage().' In Line: '.$e->getLine());
return response()->json(['code' => 403, 'message' => 'Something went wrong']);
}
but in the catch it returns that error, also in the laravel log and it tells me that it is in those lines where I have the $ name, I do not know how it is generated I have tried to enter a null, an array, an object but it does not it gives that error, how could I simulate it so I can correct it or how to fix the error?