亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 maatwebsite 和 laravel 進行查詢導出 excel

使用 maatwebsite 和 laravel 進行查詢導出 excel

PHP
holdtom 2023-06-24 15:52:57
您好,我真的是使用 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;


查看完整回答
反對 回復 2023-06-24
?
子衿沉夜

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');


查看完整回答
反對 回復 2023-06-24
  • 2 回答
  • 0 關注
  • 286 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號