Closed jeanali closed 3 years ago
Thanks for submitting the ticket. Unfortunately the information you provided is incomplete. We need to know which version you use and how to reproduce it. Please include code examples. Before we can pick it up, please check (https://github.com/Maatwebsite/Laravel-Excel/blob/3.1/.github/ISSUE_TEMPLATE.md) and add the missing information. To make processing of this ticket a lot easier, please make sure to check (https://laravel-excel.maatwebsite.nl/3.1/getting-started/contributing.html) and double-check if you have filled in the issue template correctly. This will allow us to pick up your ticket more efficiently. Issues that follow the guidelines correctly will get priority over other issues.
Is FromQuery OK with this size of data?
FromQuery chunks the query into smaller batches of data
In queue section how can I send the file to email after the queue is done?!
You have to chain a queued job, please refer to Laravel documentation on how to send an email
here is a full answer:
https://stackoverflow.com/questions/64686685/export-large-data-from-db-using-laravel-excel
``I am trying to export more than 10k data in my excel but it show time out or sometime show not reached. What is the best process to export large amount of data in excel. In the i gave mtycontroller and export code.
controller:
function excel(){ return (new UsersExport())->download('invoices.xlsx'); }
in the Export folder UsersExport.php file
`<?php
namespace App\Exports;
use App\Models\TEST;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\FromArray;
use Illuminate\Contracts\Queue\ShouldQueue;
class UsersExport implements FromQuery, WithMapping, WithHeadings,ShouldQueue { /**
@return \Illuminate\Support\Collection
*/
use Exportable;
public function query() { return TEST::query()->where('status_id','!=','12'); }
public function headings(): array { return [ 'test Id', 'test Tracking Id','test Type','customer name', 'Receiver Info','Pickup','Delivery','cash','Charge','Status','cash Payment','Paid By','Request Time','Pickup Time','Delivery Time','Time Duration' ]; }
public function map($row): array { if($row->delivery == '0' || empty($row->delivery)){ $delivery = (!empty($row->branch->name)?$row->branch->name:'Not Available'); }else{ $delivery=(!empty(\App\Models\Branch::find($row->delivery)->name)?\App\Models\Branch::find($row->delivery)->name:'Not Available'); }
$picks =\App\Models\TestLog::where('courier_id',$row->id)->where('status_id','13')->first();
return [
$row->id,
$row->tracking_id,
$row->test_type->title,
!empty($row->customer->name)?$row->customer->name:"Not Available",
$row->receiver_name.'-- '. $row->receiver_address .'-- '.$row->receiver_phone,
!empty($row->pickup->name)?$row->pickup->name:"Not Available",
!empty($delivery)?$delivery:"Not Available",
$row->cash,
$row->pricing->price,
$row->status->name,
$row->cash_status,
$row->paid_by,
date('d-m-Y h:i A',strtotime($row->created_at)),
!empty($picks->created_at)?date('d-m-Y h:i A',strtotime($picks->created_at)):"Not Available",
!empty($row->delivery_date)?date('d-m-Y h:i A',strtotime($row->delivery_date)):"Not Available",
$row->created_at->diffForHumans()
];
}
}``
Code is ok. it exports data when it has less amount of data but its occur problem when it's time to export large amount of data. Please if anyone can suggest how can i solved this when it's time to export large data
Prerequisites
Description
I have like more than 30,000 products in
DB
and I need to export them, I have two question:Is
FromQuery
OK with this size of data?In queue section how can I send the file to email after the queue is done?!
my test code