php - Laravel excel将变量传递给出口商
问题描述
我正在使用 Laravel Excel 3.1 尝试使用两个参数导出文件
web.php {路由文件}
Route::post('/Download', 'Controller@Download');
和我的控制器
public function Download(Request $request)
{
$StartDate = Input::get('StartDate');
$EndDate = Input::get('EndDate');
$exporter = app()->makeWith(UsersExport::class, compact('StartDate','EndDate'));
return $exporter->download('Summary Detail.xlsx');
}
userExporter.php
class UsersExport implements FromQuery, WithHeadings,ShouldAutoSize
{
use Exportable;
protected $StartDate,$EndDate;
public function __construct(String $StartDate,String $EndDate)
{
$this->StartDate = $StartDate;
$this->EndDate = $EndDate;
}
public function query()
{
return databaseReceipt::query()
->whereDate('created_at', '>=', $this->StartDate)
->whereDate('created_at', '<=', $this->EndDate)
->select('id','servicename',"created_at");
}
}
当我使用“00:00 01/04/2017”和“00:00 01/01/2018”等静态变量作为开始日期和结束日期时,它工作正常,这导致我传递变量不起作用
解决方案
抱歉,伙计们,我发现了问题所在<<我想,那天我很累,因为解决方案很容易
在功能下载
$S = date('Y-m-d H:i:s', strtotime(strtr($request->StartDate, '/', '-')));
$E = date('Y-m-d H:i:s', strtotime(strtr($request->EndDate, '/', '-')));
return (new UsersExport($S,$E))->download('invoices.xlsx');
只是为了清楚我的错误是因为不同的格式日期类型。顺便说一句,您可以传递尽可能多的变量和任何类型
推荐阅读
- python - 枚举列表的所有排序排列
- linux - 打印目录的完整路径
- jupyter-lab - 在谷歌云中构建 jupyterlab
- html - 如何创建在悬停时显示图像的链接组件
- r - eventReactive 使用未更改的输入重新计算已计算的对象
- git - git 忽略以点开头的文件
- javascript - 如何使用定义的代码转换 const 国家列表?
- format - Folium Layer Control:如何正确控制显示(字体大小,空间,...)?
- python - 猜数字游戏 Python 3.8
- javascript - Asp.net core 3.1 mvc ajax 发送列表
- > 到控制器