I have this piece of code Route::get('manager/ptemplate/sample-csv-download', function () { $headers = array('Content-Type' => 'text/csv'); return Response::download('properties_csv_template/property.csv', 'property.csv', $headers); })->name('template.property'); where i'm trying to do a direct download of a csv file.The file is in the public folder .However on accessing this route , the file content is shown on the browser rather than a direct download .If i refresh the page , the file now gets downloaded. I also tried with response()->download(...) but still get the same outcome.
#Response::download() stream the file rather than download.
9 messages · Page 1 of 1 (latest)
I can't reproduce this. It downloads every time. Is the user just clicking a regular link in the frontend?
Yes . A button link.
Please show the html for the link. And js if it's using any.
Sure. Action::make('Sample template')->icon('heroicon-o-arrow-down-circle')->url(route('template.property')) . PS . I'm using filamentphp.
I mean the actual html in the browser.
<a href="http://localhost:8000/manager/ptemplate/sample-csv-download" wire:navigate="" style="--c-400:var(--primary-400);--c-500:var(--primary-500);--c-600:var(--primary-600);" class="fi-btn relative grid-flow-col items-center justify-center font-semibold outline-none transition duration-75 focus-visible:ring-2 rounded-lg fi-color-custom fi-btn-color-primary fi-size-md fi-btn-size-md gap-1.5 px-3 py-2 text-sm inline-grid shadow-sm bg-custom-600 text-white hover:bg-custom-500 dark:bg-custom-500 dark:hover:bg-custom-400 focus-visible:ring-custom-500/50 dark:focus-visible:ring-custom-400/50 fi-ac-btn-action">
<!--[if BLOCK]><![endif]--> <!--[if BLOCK]><![endif]--> <svg class="fi-btn-icon h-5 w-5" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" aria-hidden="true" data-slot="icon">
<path stroke-linecap="round" stroke-linejoin="round" d="m9 12.75 3 3m0 0 3-3m-3 3v-7.5M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z"></path>
</svg> <!--[if ENDBLOCK]><![endif]-->
<!--[if ENDBLOCK]><![endif]-->
<span class="fi-btn-label">
Sample template
</span>
<!--[if BLOCK]><![endif]--> <!--[if ENDBLOCK]><![endif]-->
<!--[if BLOCK]><![endif]--> <!--[if ENDBLOCK]><![endif]-->
</a>```
Looks fine to me. Could you try testing with a plain <a> tag without any Livewire magic? That's how I tested it, and it worked fine in both Firefox and Chrome.
Doing it this way without the livewire magic works as expected .