barryvdh / laravel-dompdf

A DOMPDF Wrapper for Laravel
MIT License
6.62k stars 965 forks source link

Passing variables in Redirect after downloading the PDF file #985

Open awaisharal opened 1 year ago

awaisharal commented 1 year ago

Hello @everyone, I want to report this issue that I am facing while downloading the PDF file. To download the PDF it is mandatory to use a return statement in my controller that automatically redirects me back to the blade file. But I need to pass a few variables in the redirect so that I can use them on the view file.

$pdf = PDF::loadHTML($pdfContent);
return $pdf->download($filename);

I tried using with() compact() and nothing seems to work. return $pdf->download($filename)->with($var1, $var2);

I have not found any solution for this in the docs as well. Please fix this issue.

parallels999 commented 1 year ago

Please fix this issue.

Just because you don't know how to do it doesn't mean it's an issue https://laravel.com/docs/10.x/responses#redirecting-with-flashed-session-data https://stackoverflow.com/a/25625653

awaisharal commented 1 year ago

It's definitely an issue. I already tried sending the values as Session. The problem is when you download a file it does not actually reload the page and without reloading the view file does not catch the Session values

Please see the example below:

$pdf = PDF::loadHTML($pdfContent);
\Session::flash('downloaded', $bundle);
return $pdf->download($filename);

As you can see I am sending the session value before downloading the file. I am handling the session value in my view file:

@if(Session::has('downloaded'))
    <p>Download Completed</p>
@endif

After downloading the file I don't see this line printed. But when I reload the page it is showing the "Download Completed" Text. I hope you are getting my point.

parallels999 commented 1 year ago

The problem is when you download a file it does not actually reload the page and without reloading the view file does not catch the Session values

tell that to laravel, that is the reason why it is not a bug, it is an expected behavior, it seems that you did not take the trouble to read the links that I left you