laravel collection all code example
Example 1: laravel collection methods
$collection = collect([1,2,3,4]);
$collection->each(function($item){
return $item*$item;
});
// [1,4,9,16]
Example 2: collection get first element laravel
$first = $msgs->first(); // this does ->take(1) under the hood
Example 3: collection methods laravel
$collection->each(function ($item, $key) {
hj
});