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

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -