微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Maatwebsite调用数组中的成员函数all

如何解决Maatwebsite调用数组中的成员函数all

我正在尝试从表中生成/下载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');

是什么原因导致此问题,以及如何解决

解决方法

似乎我缺少功能。我还需要将其转换为集合。此功能解决了我的问题。

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

不仅仅是返回

return DB::select($query);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。