I have configured Laravel queue with horizon and everything is working perfectly, but when I start exporting the file, the horizon shows completed job while it gives me empty Excel file with 6kb in cache folder.
Here’s my code:
app/exports/FullReportExport.php
<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithChunkReading;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\Models\Admin\FullReport;
class FullReportExport implements FromQuery, WithChunkReading, ShouldQueue
{
use Exportable;
public function query()
{
return FullReport::query();
}
public function chunkSize(): int
{
return 5000;
}
}
app\http\FullReportController.php
<?php
namespace App\Http\Controllers\Admin\Reports;
use App\Http\Controllers\Controller;
use App\Exports\FullReportExport;
class FullReportController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function export()
{
(new FullReportExport)->store('invoices.xlsx');
}
}
worker.log
[2023-09-20 04:05:10][10] Processing: Maatwebsite\Excel\Jobs\QueueExport
[2023-09-20 04:05:10][10] Processed: Maatwebsite\Excel\Jobs\QueueExport
laravel-worker.ini
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=/Applications/MAMP/bin/php/php7.4.33/bin/php /Users/cairocoder/Sites/localhost/myapp/artisan queue:work redis --timeout=3600
autostart=true
autorestart=true
user=cairocoder
numprocs=8
redirect_stderr=true
stdout_logfile=/Users/cairocoder/Sites/localhost/myapp/storage/logs/worker.log
In the examples , chunks works with ToModel impl.
@Mate even without chunks, it didn’t work.
Maybe you could verify the plain sql executed.