Define collections in Laravel

Collections provide a convenient way to work with arrays of data. Laravel collections are an extension of the PHP array object, but they come with a variety of powerful methods that make manipulating and interacting with arrays more expressive and readable.

Allows you to chain its methods to perform fluent mapping and reducing of the underlying array. Collections are immutable, meaning every Collection method returns an entirely new Collection instance.

You can perform various operations on collections using the available methods. Some common methods include map, filter, each, pluck, count, sum, avg, max, min, etc.

$collection = collect(['taylor', 'abigail', null])->map(function (string $name) {
    return strtoupper($name);
})->reject(function (string $name) {
    return empty($name);
});