【问题标题】:Maatwebsite Call to a member function all() on arrayMaatwebsite 调用数组上的成员函数 all()
【发布时间】: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');

是什么导致了这个问题,我该如何解决?

【问题讨论】:

    标签: maatwebsite-excel


    【解决方案1】:

    似乎我缺少一个功能。我还需要它转换为收藏。这个功能解决了我的问题。

    return collect(DB::select($query));

    不仅仅是返回

    return DB::select($query);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-15
      • 2017-10-03
      • 2021-09-04
      • 2016-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多