I am attempting to get filtered records from my Contact model based on the unsusbcribe column being set to 0 or null and then take a subset of those records and chunk 8 of those at a time into a closure - this is the following code I have tried:
$contacts = Contact::where('unsubscribed', 0)
->orWhereNull('unsubscribed')
->inRandomOrder()->take(40)->get();
$contacts->chunk(8, function ($chunk) {
dump('Processing batch...');
dump($chunk->toArray());
dump('Random dump process executed.');
});
However the dump does not get executed, since I have all ready confirmed and tested there are enough records to return to justify the chunk what am I doing wrong and please keep in mind I am doing this inside a Feature test from the terminal.
UPDATE: Have also tried:
Contact::where('unsubscribed', 0)
->orWhereNull('unsubscribed')
->take(40)
->chunk(8, function (Collection $contacts) {
dump("We on!!!");
});
as per suggestion of @paper fjord
Thank you!