eloquent collection laravel code example
Example 1: laravel collection methods
$collection = collect([1,2,3,4]);
$collection->each(function($item){
return $item*$item;
});
Example 2: get item from collection that match
$artist = 'Vincent John Doe';
$art_collection = $paintings->filter(function ($painting) use ($artist) {
return $painting->artist == $artist;
});
foreach($paintings as $painting) {
if($painting->artist == $artist) {
$art_collection[] = $painting;
}
}
Example 3: collection methods laravel
$collection->each(function ($item, $key) {
hj
});
Example 4: eloquent map collection
Example 5: laravel collection namespace
Illuminate\Database\Eloquent\Collection