I'm making a form with Laravel 8 that at the end downloads a pdf and shows me a message but I can't make it show me both. Either it downloads the pdf and doesn't show anything or it only shows the msg and doesn't download the pdf. These are my controllers
Function that generates the pdf
protected function pdf($data){
$pdf = \PDF::loadView('orden/ordenPDF', $data);
return $pdf->download('archivo.pdf');
}
And here I call him and try to return him with a message
$pdf=$this->pdf($data);
$mensaje='La orden de compra se ha generado con éxito, se ha descargado un archivo PDF. Si desea
visualizar nuevamente la orden generada diríjase a la opción "Orden de compra -> Órdenes de
compra."';
return $pdf;
return back()->with('success',$mensaje)
if i just use return $pdf
it i download the pdf without message. If I only use return back()->with('success',$mensaje)
it, it returns only the message that it is.
I tried with return $pdf->with('success',$mensaje);
but it throws the following error: BadMethodCallException Method Illuminate\Http\Response::with does not exist.
At the end I left the controller with a
return $pdf
and I passed a js function to the view form to update the page when pressing the "enter" button. This is how I solved the problem.VIEW:
CONTROLLER:
This way I download the pdf and at the same time it updates the page for 1 second to show the message.