【发布时间】:2020-09-14 13:16:58
【问题描述】:
我正在尝试从表格中生成/下载 excel,但一直显示错误 Call to a member function all() on array
注意:我已经删除了这里的构造函数
use Illuminate\Support\Facades\DB;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\Exportable;
class VehicleRequestExportDestination implements FromCollection
{
use Exportable;
public function collection()
{
$this->dateFrom = $this->dateFrom . ' 00:00:00.000';
$this->dateTo = $this->dateTo . ' 23:59:59.999';
$query = "
SELECT
SUBSTRING(destination,LOCATE('|',destination),LENGTH(destination)) AS dest,
COUNT(destination) AS total
FROM dispatches
WHERE
addedDate
BETWEEN
'" . $this->dateFrom . "' AND '" . $this->dateTo . "'
GROUP BY
destination
ORDER BY
total DESC
LIMIT 10";
return DB::select($query);
}
}
这就是我从控制器中调用它的方式
return (new VehicleRequestExportDestination("2000-05-05","2030-05-05"))->download('Frequent Destination.xlsx');
是什么导致了这个问题,我该如何解决?
【问题讨论】: