您好,我真的是使用 maatwebsite 的新手,已經閱讀了文檔,但找不到它,有人可以給我一個關于使用 maatwebsite 導出 excel 后執行查詢的想法嗎?這是我的代碼:public function export(){ Excel::download(new KodePosExport, 'KodePos.xlsx'); KodePos::query()->truncate(); return redirect('/')->with('success', 'All good!');}它可以重定向到我想要的頁面并截斷數據,但不能導出 Excel,我該怎么做?謝謝如果使用此功能導出 Excel 工作正常,但不包含查詢public function export(){ return Excel::download(new KodePosExport, 'KodePos.xlsx'); //KodePos::query()->truncate(); // return redirect('/')->with('success', 'All good!');}
2 回答

MMMHUHU
TA貢獻1834條經驗 獲得超8個贊
$download = Export::download(...);
KodePos::query()->truncate();
return $download;

子衿沉夜
TA貢獻1828條經驗 獲得超3個贊
我可以在這里建議兩種解決方案;
可終止中間件
有時,中間件可能需要在 HTTP 響應發送到瀏覽器后執行一些工作。如果您在中間件上定義了終止方法并且您的 Web 服務器使用 FastCGI,則在響應發送到瀏覽器后將自動調用終止方法。
創建異步作業并在下載過程之前延遲觸發它(您的隊列驅動程序不應該是
sync
,redis
是一個很好的候選者)
class KudeposTruncater extends Job implements ShouldQueue
{
? ? use InteractsWithQueue;
? ??
? ? public function handle()
? ? {
? ? ? ? KodePos::query()->truncate();
? ? }
}
\Queue::later(15, new KudeposTruncater());
return Excel::download(new KodePosExport, 'KodePos.xlsx');
- 2 回答
- 0 關注
- 286 瀏覽
添加回答
舉報
0/150
提交
取消