How To manage collection data in laravel?
Rohit Urane

Rohit Urane @rohiturane

About: Laravel & Vuejs Developer

Location:
Pune, MH, IND
Joined:
Jun 5, 2020

How To manage collection data in laravel?

Publish Date: Mar 10 '22
2 1

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

Comments 1 total

Add comment