#I'm using Laravel Excel to handle exports and imports with more than 300K records, but I'm facing me
7 messages · Page 1 of 1 (latest)
You'd need to use chunked reading and maybe even batched inserts;
https://docs.laravel-excel.com/3.1/imports/chunk-reading.html
https://docs.laravel-excel.com/3.1/imports/batch-inserts.html
The thing is, you're loading a whole lot at once into memory, so by using chunked reading you're only reading/processing part of the file.
Really Appreciate Sir!! and is the same as export?
An export is slightly different, but you could use an iterator along with a cursor (I think) https://laravel.com/docs/12.x/eloquent#cursors
Or use a chunked query. Kinda depends on your needs
Sorry for the late Sir, I was already using chunks "public function chunkSize(): int
{
return 5000;
}" ```php class StudentExport implements FromQuery, ShouldAutoSize, ShouldQueue, WithChunkReading, WithColumnWidths, WithHeadings, WithStyles
{
use Exportable;
public function query()
{
return Employee::select('full_name','emp_id');
}
public function headings(): array
{
return [
'Full Name',
'Employee ID',
];
}
public function columnWidths(): array
{
return [
'A' => 30,
'B' => 30,
];
}
public function styles(Worksheet $sheet)
{
return [
1 => [
'font' => ['bold' => true],
],
'C' => ['alignment' => ['horizontal' => 'center']],
];
}
public function chunkSize(): int
{
return 5000;
}
}```
This might help: https://www.youtube.com/watch?v=CAi4WEKOT4A
In this video, we explore different ways to import large CSV files in Laravel, benchmarking each approach and discussing their pros and cons. From simple collection-based imports to high-performance concurrent processing - let's try it out together.
📜 Repository & Additional Improvements:
https://github.com/christophrumpel/laravel-import-mil...
let me check again! thanks a lot Sir