The Collection class provides a convenient wrapper for working on an array of data. we are to manage collection in laravel. Below is an example of a collect helper which creates a new collection of instances, processes upper case on the element, and removes the nullable element.
$collection = collect(['taylor', 'abigail', null])->map(function ($name) {
return strtoupper($name);
})
->reject(function ($name) {
return empty($name);
});
Creating Collection-
The collect helper returns a new collection instance for the given array. Every Eloquent query returns collection instances. Afterward, we will manage collection data in laravel.
$collection = collect([1,2,4]);
Top comments (1)
Perfect post