Not sure what you think chunk will achieve?
Its purpose is to reduce memory load on the server, which is completely negated if you just sit in a loop concatenating the results?
I don't know what 'returning array as true' possibly means?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have data base table with thousands of rows, i am trying to use the chunk method in laravel to return the data to view , but it is returning array as true, can some one help me?
$keys = LanguageMapper::where('lag_id_fk', 2)->where('module_id_fk', $mod_id)
->chunk(250, function ($keys) use($other) {
foreach ( $keys as $i => $key )
{
$finalObj[$i]['key'] = $key['key_name'];
$finalObj[$i]['en_text'] = $key['text'];
$finalObj[$i]['trans_text'] = isset($other[$key['key_name']]['text']) ? $other[$key['key_name']]['text'] : '';
$finalObj[$i]['trans_key_id'] = isset($other[$key['key_name']]['id']) ? $other[$key['key_name']]['id'] : 0;
$finalObj[$i]['trans_key_status'] = isset($other[$key['key_name']]['status']) ? $other[$key['key_name']]['status'] : 0;
}
return $finalObj;
});
And i cannot use pagination because i am iterating results. please ignore the arrays as it is not the whole code, i just need to know how i should return the results of foreach.
Please or to participate in this conversation.