Reputation: 611
I'm working on a local project with Laravel 5. I'm trying to grab what could potentially be (or become) huge amounts of data. I'm doing so
$tickets = Ticket::getResolvedTicketsBetween($start,$end)->chunk(200, function($chunkOfTickets){
foreach ($chunkOfTickets as $ticket) {
echo $ticket->id;
}
});
The problem is I'm getting the error
array_chunk() expects parameter 3 to be boolean, object given
What am I doing wrong? Can someone please help me, I'm following the documentation accordingly... I think...
Upvotes: 4
Views: 6492
Reputation: 24549
I just did a search of the Laravel framework and the only usage is in the Collection
class, which has a chunk()
function not to be confused with the chunk()
function of the query builder class.
If getResolvedTicketsBetween()
makes a call to get()
then it will end up returning a Collection. If you want to be able to continue building on the query, remove the call to get()
.
My guess at how your code might look:
function getResolvedTicketsBetween($start, $end) {
// Dont do this
// return Ticket::where('created_at', '>=', $start)->where('created_at', '<=', $end)->where('state','=','Resolved')->get()
// Do this instead (returns Query Builder instance)
return Ticket::where('created_at', '>=', $start)->where('created_at', '<=', $end)->where('state','=','Resolved');
}
Upvotes: 2