I am currently using Laravel Fast-Excel with the Chunks method: https://github.com/rap2hpoutre/fast-excel?tab=readme-ov-file#export-large-collections-with-chunk
I have the following in my controller:
public function download_excel(Request $request)
{
return (new FastExcel(usersGenerator()))->download('file.xlsx');
}
public function usersGenerator() {
foreach (User::cursor() as $user) {
yield $user;
}
}
In order to actually trigger the download from the browser, I have a button that opens the route in a new tab:
document.querySelector("#excel-download-button").addEventListener("click", function(event) {
window.open('/excel-download', '_blank');
});
So the tab is opened for a split second, the download starts and the tab closes.
But I want to skip this behavior of using the new tab.
Is it possible to download it directly from a fetch request?
Something like this:
fetch('/excel-download')
.then(response => {
// ... download ...
});
I couldn't find the way to do that