I am trying to process some of the records in 'message' table using chunk method of laravel 5.2 query builder. But I am unable to get processed ids in array outside of the query builder.
I can access it declaring variable as global but is there any other way?
I need this after completion of chunk because if I update record in same loop then chunk will skip records. As chunk works like pagination.
Using global (Working):
global $m_ids;
DB::table("messages")
->where('processed','0')
->chunk(100, function ($messages){
foreach ($messages as $message) {
$GLOBALS['$m_ids'][] = $message->id;
}
});
echo "<pre>"; print_r($GLOBALS['$m_ids']); die;