Download multiple files from laravel php?

0

Cordial greeting colleagues, I have the following question, I am developing an application in laravel php, which should export a word file and excel after performing certain processes, my problem is when downloading these files, as I need them to download both at the press of a button, I'm using the statement return response () -> download ('cot1.docx'), the problem is that when using it twice, it will only take the first return and download the first file, the other does not Take my code is this:

For the word

$TemplateProcessor= new TemplateProcessor(Storage_path('Estudio_conexion.docx'));


// $TemplateProcessor->setValue('var',$saludo);
$TemplateProcessor->setValue('algoo',$definicion);

$TemplateProcessor->setValue('nombre_cliente' ,$nombre_cli);
$TemplateProcessor->setValue('nombre_empresa' ,$empresa_cli);
$TemplateProcessor->setValue('Correo',$correo_cli);
$TemplateProcessor->setValue('direccion',$direccion_cli);
$TemplateProcessor->setValue('fecha',$fecha_cli);
$TemplateProcessor->setValue('referencia',$referencia_);
$TemplateProcessor->setValue('objetivo',$objetivo_);
$TemplateProcessor->setValue('nom_est',$nombre_proyecto);
$TemplateProcessor->setValue('precio_est','$'.($precio_est2));
$TemplateProcessor->setValue('precio_iva','$'.$precio_iva2);
$TemplateProcessor->setValue('total','$'.($total2));
$TemplateProcessor->setValue('acti1',$act1);
$TemplateProcessor->setValue('acti2',$act2);
$TemplateProcessor->setValue('mtdg' ,$desc_met);
// $TemplateProcessor->setValue('firma',$firma);

//Guardamos el documento y lo retornamos como descarga
$TemplateProcessor->saveAs('cot1.docx');

 return response()->download('cot1.docx');

For the excel:

/Abrimos la plantilla
$sheet = \PhpOffice\PhpSpreadsheet\IOFactory::load(Storage_path('cotizacion_excel.xlsx'));

$sheet->setActiveSheetIndex(1);
$activeSheetacti=$sheet->getActiveSheet();
$activeSheetacti->setCellValue('A1',$nombre_proyecto);
$activeSheetacti->setCellValue('A2',$empresa_cli);
$activeSheetacti->setCellValue('A3',$fecha_cli);
//Creamos el writer 
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($sheet);

//Guardamos la copia de la plantilla con los datos personaizados
$writer->save($empresa_cli.'_Cot_Rev0.xlsx');

//Se descarga la plantilla
return response()->download($empresa_cli.'_Cot_Rev0.xlsx');

All this is in the same function, since both templates receive the data by the same form. Try downloading both files with a single return in this way:

return Response()->download(["cot1.docx","$empresa_cli.'_Cot_Rev0.xlsx"]);

But it does not work that way, could you give me some idea of how to download both files by the browser, taking into account that both are in the same function?

    
asked by Kevin Burbano 04.05.2018 в 20:45
source

0 answers