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

排队时Laravel Excel不起作用

如何解决排队时Laravel Excel不起作用

我有以下 laravel excel 导出:

namespace App\Admin\Exports\Items;

use App\Flare\Models\Item;
use Illuminate\Contracts\Queue\ShouldQueue;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromQuery;

class ItemsExport implements FromQuery,ShouldQueue {

    use Exportable;

    public function query() {
        return Item::all();
    }
}

在此控制器操作中调用

public function export() {

    (new ItemsExport)->queue('items.xlsx')->chain([
        new ExportItemsEmail(auth()->user()),]);

    return redirect()->back()->with('success','File will be emailed to you once done.');
}

这个表有超过 5k 条记录

Horizo​​n 正确推送作业,但其中一个失败:

Maatwebsite\Excel\Jobs\AppendQueryToSheet

ArgumentCountError:函数 Illuminate\Support\Collection::get() 的参数太少,0 传递 > 在 /home/person/Documents/flare/vendor/maatwebsite/excel/src/Jobs/AppendQueryToSheet.PHP 第 96 行在 /home/person/Documents/flare/vendor/laravel/framework/src/Illuminate/Collections/Collection.PHP:407

中至少有 1 个预期

这不是您将应该对查询结果分块的大型导出进行排队的方式吗?

我必须附加一个作业,所以我不能只是存储它。 我做错了什么吗?

解决方法

避免错误的正确方法是使用 Item::query(),因为所有都将返回一个集合。

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