In this tutorial, we will see how to use chunk method in laravel.
Laravel eloquent chunk method break the large group of data set into smaller group of data set.
Example 1:
/**
* The attributes that are mass assignable.
*
* @var array
*/
public function index()
{
$users = User::all()->chunk(3);
dd($users);
}
Example 2:
Controller :
/**
* The attributes that are mass assignable.
*
* @var array
*/
public function index()
{
$users = User::all();
return view('users.user',compact('users'));
}
Blade File :
@foreach($users->chunk(3) as $row)
{{ $row }}
@endforeach
I hope this example helps you.