DEV Community

Rohit Urane
Rohit Urane

Posted on

How To manage collection data in laravel?

How To manage collection data in laravel
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);
});
Enter fullscreen mode Exit fullscreen mode

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]);
Enter fullscreen mode Exit fullscreen mode

Read More

Top comments (1)

Collapse
 
coderlegi0n profile image
CoderLegion

Perfect post