chunk laravel code example
Example 1: how to return chunk data laravel
$count = 0;
DB::table('users')->chunk(200, function($users) use (&$count)
{
Log::debug(count($users)); // will log the current iterations count
$count = $count + count($users); // will write the total count to our method var
});
Log::debug($count); // will log the total count of records
Example 2: laravel chunk select
DB::table('users')->chunk(100, function($users)
{
foreach ($users as $user)
{
//
}
});
Example 3: laravel 8 orderby
$flights = App\Models\Flight::where('active', 1)
->orderBy('name', 'desc')
->take(10)
->get();