如何使用Laravel Excel在 – > download()之后redirect
无法在Laravel Excel的文档中find如何在download()之后redirect()。 我试过这样做
Excel::load('/bills/bill.template.xlsx', function($doc) { $sheet = $doc->setActiveSheetIndex(0); $sheet->setCellValue('G21', '{buyer}'); })->download('xlsx'); return redirect('/')->with('notification','custom msg');
但它不起作用。
要下载,您必须执行返回语句以及下载。
return Excel::load('/bills/bill.template.xlsx', function($doc) { $sheet = $doc->setActiveSheetIndex(0); $sheet->setCellValue('G21', '{buyer}'); })->download('xlsx');
它不会下载自己,如果你不把它发送到视图。 所以,就我所知,没有像下载和redirect这样的事情。
你可以做的是将Excel文件存储在laravel的存储文件夹(或任何你喜欢的地方)的某个地方,然后redirect。 在新的页面中,你可以用JS打开一个隐藏的页面,在那个页面下载你想要给用户的excel文件。
看来这是不能做的,但有一个解决方法,你可以尝试一个类似的问题:
在Laravel下载后如何redirect?
基本上你redirect到最后一页,然后开始下载:
Session::flash('download.in.the.next.request', 'filetodownload.pdf'); return Redirect::to('/');
然后在你的观点看起来像这样:
<html> <head> @if(Session::has('download.in.the.next.request')) <meta http-equiv="refresh" content="5;url={{ Session::get('download.in.the.next.request') }}"> @endif <head> <body> ... </body> </html>
检查上面的链接进一步的解释。