【发布时间】:2021-07-27 15:01:49
【问题描述】:
我有一个单选组,可以过滤我的表格以显示项目是活动的、非活动的还是两者兼而有之。还有一个按钮,我用来导出表格的 excel 文档。我当前的按钮下载所有记录。我想要的是基于过滤器导出文档,因此如果选择并显示活动并按下下载按钮,则只会导出活动记录
我的代码: 控制器:
public function filter()
{
$energy = Energy::where('isredundant', 0)->paginate(10);
return view('admin.staff', ['staff1' => $staff1]);
}
public function filtered()
{
$energy = Energy::where('isredundant', 1)->paginate(10);
return view('admin.staff', ['staff1' => $staff1]);
}
public function export()
{
return Excel::download(new UsersExport, 'allrecords.xlsx');
}
public function export()
{
return Excel::download(new UsersExport, 'AllReport.xlsx');
}
public function exportactive()
{
return Excel::download(new UsersExportactive, 'ActiveRecords.xlsx');
}
public function exportredundant()
{
return Excel::download(new UsersExportredundant, 'RedundantRecords.xlsx');
}
我的按钮:
<div> <a class="btn btn-warning" href="/export_excel/excel">Generate Report</a></div>
我尝试使用 3 个不同的按钮,但看起来很乱。我敢肯定有一个更简单的方法
【问题讨论】:
-
对于初学者,您的两个方法具有相同的名称:
export。这需要解决。 -
我想通了
-
欢迎,为了改善您在 SO 上的体验,请 take the tour 并阅读 how to ask、On Topic question,然后查看 Question Check list、perfect question 以及如何创建 @987654326 @
-
从昨天开始,来自另一个帐户的问题敲响了 :)
-
你能链接这样的问题吗?本来会有更多帮助
标签: php html laravel laravel-8