Never mind, I got it. The streamDownload() method was causing the cache to be cleared. When I stopped using it and switched to file_put_contents() instead, it worked.
Opening a PDF File Clears My Session Data
I'm working on a Laravel app that has several user documents in DOCX and PDF format to download. When a user clicks on the DOCX file, they open, no problem.
But when a user clicks on any PDF file, it opens it in the browser. Then, when the user goes back to and clicks another link on the site, all the session data is lost.
The trigger that is clearing the session data is clicking a link to any PDF file.
I tried setting the new HTML "download" attribute to download instead of opening the PDFs, but it doesn't help, the session data is still lost.
What is causing the session data to get cleared when a PDF is loaded?
Here is my document route:
Route::get('/document', function () { return response()->streamDownload(function () {
echo base64_decode(App\CRM::document(request()->input('i'), request()->input('n')));
}, Portal::userFriendlyFileName(request()->input('n')), ['Content-Type' => Illuminate\Http\Testing\MimeType::from(request()->input('n'))], 'inline');
})->name('document'); And my anchor link:
I tried putting my Document route inside the "web" group, but that didn't work.
My session driver is set to file with a lifetime of 9999, 'expire_on_close' => false,
How can I click on a PDF and keep my session data?
Please help, I don't know what to do. I am using Laravel 7.15.
Please or to participate in this conversation.