So what happens when it redirects? Does the url change to the correct "Download" page? or?
Aug 27, 2021
3
Level 1
Laravel Does Not Download Excel File Automatically After Redirecting
I'm suing "maatwebsite/excel": "^3.1" with Laravel 8 and I have made an Export class for downloading an Excel file which is working fine.
And the route which calls this request goes like this:
Route::get('/export-excel',[BatchController::class,'exportIntoExcel'])->name('batch.export.excel');
So at the Controller method, I tried redirecting to route batch.export.excel after an insertion process:
public function priceChanges($pcode, $sprice, $fprice, $seller)
{
$insertChanges = \App\Models\Robo\PriceChange::create([
'product_code' => $pcode,
'before_update' => $sprice,
'rival_price' => $fprice,
'rival_name' => $seller,
'change_price' => "100",
'after_update' => 0,
]);
return redirect(route('batch.export.excel'));
}
So it should be downloading the Excel file when calling redirect(route('batch.export.excel') but it does not somehow.
However if I manually go to export-excel url on browser, the file gets downloaded properly.
So how to download this Excel file automatically after a Controller method ran ?
Please or to participate in this conversation.