Collections
Collections
Introduction
The Illuminate\Support\Collection
class provides a fluent, convenient wrapper for working with arrays of data. For example, check out the following code. We'll use the collect
helper to create a new collection instance from the array, run the strtoupper
function on each element, and then remove all empty elements:
$collection = collect(['taylor', 'abigail', null])->map(function ($name) { return strtoupper($name); }) ->reject(function ($name) { return empty($name); });
As you can see, the Collection
class allows you to chain its methods to perform fluent mapping and reducing of the underlying array. In general, every 登录查看完整内容