eloquent - Laravel chunk returns null -
i'm needing chunk query it's making php run out of memory, below code dumps null
:
$chunked = $query->chunk(25, function ($events) { //dd($events); }); dd($chunked);
however, when below, dumps first chunk of 25:
$chunked = $query->chunk(25, function ($events) { dd($events); }); //dd($chunked);
no combination of changing dd($events);
likes of return $events
, return true
, iterating on each item in each chunk , returning - works.
am stupid/doing wrong or not working should?
chunk()
helper method can use on instance of query builder or eloquent builder. in both cases, method returns void
:
this means $chunked
variable empty.
the syntax need employ following:
query builder
db::table('users')->chunk(100, function($users) { foreach ($users $user) { // } });
eloquent
flight::chunk(200, function ($flights) { foreach ($flights $flight) { // } });
basically, need use loop within callback function of chunk()
modify results.
Comments
Post a Comment