Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

I know it is probably outdated.. But. do you mean something like:

$allProperties = collect();

DB::table('property')->chunk(5000, function($properties) use ($allProperties) {
    foreach($properties as $property){
         // Do something here..
         $allProperties->push($property);
    }
});

foreach ($allProperties as $property)...

Though note: using above you would probably produce the same memory allocation error as eventually you will gather the same collection as without chunking. You might want to take only required fields in collection not to consume all the memory (eg. taking only ids into $allProperties).

0

You can do like this:

$result = [];

DB::table('property')->chunk(5000, function($properties) use (&$result){
    $result[] = $properties->toArray();
})

dd($result[0]);
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.