我正在使用 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');
}
用户导出器.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');
只是为了说明我的错误是因为不同的格式日期类型。顺便说一句,您可以根据需要传递尽可能多的变量和任何类型
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句