Laravel Excel is not working when queuing

Viewed 1494

I have the following laravel excel export:

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();
    }
}

Which is called in this controller action:

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.');
}

There over 5k records for this table

Horizon pushes the job properly but one of them fails:

Maatwebsite\Excel\Jobs\AppendQueryToSheet

ArgumentCountError: Too few arguments to function Illuminate\Support\Collection::get(), 0 passed > in /home/person/Documents/flare/vendor/maatwebsite/excel/src/Jobs/AppendQueryToSheet.php on line 96 and at least 1 expected in /home/person/Documents/flare/vendor/laravel/framework/src/Illuminate/Collections/Collection.php:407

Is this not how you would queue up a large export that should chunk the results of the query?

I have to append a job so I can't just store it. Am I doing something wrong?

1 Answers

The proper way to avoid the error is to use Item::query() as all will return a collection.

Related