interface Enumerable implements Arrayable, Countable, IteratorAggregate, Jsonable, JsonSerializable

Methods

array
toArray()

Get the collection of items as a plain array.

string
toJson(int $options = 0)

Get the collection of items as JSON.

static Enumerable
make(Arrayable|iterable|null $items = [])

Create a new collection instance if the value isn't one already.

static Enumerable
times(int $number, callable|null $callback = null)

Create a new instance by invoking the callback a given amount of times.

static Enumerable
range(int $from, int $to, int $step = 1)

Create a collection with the given range.

static Enumerable
wrap(mixed $value)

Wrap the given value in a collection if applicable.

static mixed
unwrap(mixed $value)

Get the underlying items from the given collection if applicable.

static Enumerable
empty()

Create a new instance with no items.

array
all()

Get all items in the enumerable.

float|int|null
average(callable|string|null $callback = null)

Alias for the "avg" method.

float|int|null
median(string|array|null $key = null)

Get the median of a given key.

array|null
mode(string|array|null $key = null)

Get the mode of a given key.

static<int, mixed>
collapse()

Collapse the items into a single enumerable.

bool
some(mixed $key, mixed $operator = null, mixed $value = null)

Alias for the "contains" method.

bool
containsStrict(mixed $key, mixed $value = null)

Determine if an item exists, using strict comparison.

float|int|null
avg(callable|int|string|null $callback = null)

Get the average value of a given key.

bool
contains(mixed $key, mixed $operator = null, mixed $value = null)

Determine if an item exists in the enumerable.

bool
doesntContain(mixed $key, mixed $operator = null, mixed $value = null)

Determine if an item is not contained in the collection.

crossJoin(Arrayable|iterable ...$lists)

Cross join with the given lists, returning all possible permutations.

never
dd(mixed ...$args)

Dump the collection and end the script.

dump(mixed ...$args)

Dump the collection.

diff(mixed $items)

Get the items that are not present in the given items.

diffUsing(mixed $items, callable $callback)

Get the items that are not present in the given items, using the callback.

diffAssoc(Arrayable|iterable $items)

Get the items whose keys and values are not present in the given items.

diffAssocUsing(Arrayable|iterable $items, callable $callback)

Get the items whose keys and values are not present in the given items, using the callback.

diffKeys(Arrayable|iterable $items)

Get the items whose keys are not present in the given items.

diffKeysUsing(Arrayable|iterable $items, callable $callback)

Get the items whose keys are not present in the given items, using the callback.

duplicates(callable|string|null $callback = null, bool $strict = false)

Retrieve duplicate items.

duplicatesStrict(callable|string|null $callback = null)

Retrieve duplicate items using strict comparison.

each(callable $callback)

Execute a callback over each item.

eachSpread(callable $callback)

Execute a callback over each nested chunk of items.

bool
every(mixed $key, mixed $operator = null, mixed $value = null)

Determine if all items pass the given truth test.

except(mixed $keys)

Get all items except for those with the specified keys.

filter(callable|null $callback = null)

Run a filter over each of the items.

mixed
when(mixed $value, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

mixed
whenEmpty(callable $callback, callable|null $default = null)

Apply the callback if the collection is empty.

mixed
whenNotEmpty(callable $callback, callable|null $default = null)

Apply the callback if the collection is not empty.

mixed
unless(mixed $value, callable $callback, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

mixed
unlessEmpty(callable $callback, callable|null $default = null)

Apply the callback unless the collection is empty.

mixed
unlessNotEmpty(callable $callback, callable|null $default = null)

Apply the callback unless the collection is not empty.

where(callable|string|null $key, mixed $operator = null, mixed $value = null)

Filter items by the given key value pair.

whereNull(string|null $key = null)

Filter items where the value for the given key is null.

whereNotNull(string|null $key = null)

Filter items where the value for the given key is not null.

whereStrict(callable|string|null $key, mixed $value)

Filter items by the given key value pair using strict comparison.

whereIn(string $key, Arrayable|iterable $values, bool $strict = false)

Filter items by the given key value pair.

whereInStrict(string $key, Arrayable|iterable $values)

Filter items by the given key value pair using strict comparison.

whereBetween(string $key, Arrayable|iterable $values)

Filter items such that the value of the given key is between the given values.

whereNotBetween(string $key, Arrayable|iterable $values)

Filter items such that the value of the given key is not between the given values.

whereNotIn(string $key, Arrayable|iterable $values, bool $strict = false)

Filter items by the given key value pair.

whereNotInStrict(string $key, Arrayable|iterable $values)

Filter items by the given key value pair using strict comparison.

whereInstanceOf(string|array $type)

Filter the items, removing any items that don't match the given type(s).

mixed
first(callable|null $callback = null, mixed $default = null)

Get the first item from the enumerable passing the given truth test.

mixed
firstWhere(callable|string $key, mixed $operator = null, mixed $value = null)

Get the first item by the given key value pair.

static<int, mixed>
flatten(int|float $depth = INF)

Get a flattened array of the items in the collection.

TKey>
flip()

Flip the values with their keys.

mixed
get(mixed $key, mixed $default = null)

Get an item from the collection by key.

groupBy(callable|array|string $groupBy, bool $preserveKeys = false)

Group an associative array by a field or using a callback.

keyBy(callable|array|string $keyBy)

Key an associative array by a field or using a callback.

bool
has(mixed $key)

Determine if an item exists in the collection by key.

bool
hasAny(mixed $key)

Determine if any of the keys exist in the collection.

string
implode(callable|string|null $value, string|null $glue = null)

Concatenate values of a given key as a string.

intersect(mixed $items)

Intersect the collection with the given items.

intersectUsing(mixed $items, callable $callback)

Intersect the collection with the given items, using the callback.

intersectAssoc(mixed $items)

Intersect the collection with the given items with additional index check.

intersectAssocUsing(mixed $items, callable $callback)

Intersect the collection with the given items with additional index check, using the callback.

intersectByKeys(mixed $items)

Intersect the collection with the given items by key.

bool
isEmpty()

Determine if the collection is empty or not.

bool
isNotEmpty()

Determine if the collection is not empty.

bool
hasSole(callable|string|null $key = null, mixed $operator = null, mixed $value = null)

Determine if the collection contains a single item, optionally matching the given criteria.

bool
hasMany(callable|string|null $key = null, mixed $operator = null, mixed $value = null)

Determine if the collection contains multiple items, optionally matching the given criteria.

string
join(string $glue, string $finalGlue = '')

Join all items from the collection using a string. The final items can use a separate glue string.

TKey>
keys()

Get the keys of the collection items.

mixed
last(callable|null $callback = null, mixed $default = null)

Get the last item from the collection.

TMapValue>
map(callable $callback)

Run a map over each of the items.

mapSpread(callable $callback)

Run a map over each nested chunk of items.

mapToDictionary(callable $callback)

Run a dictionary map over the items.

mapToGroups(callable $callback)

Run a grouping map over the items.

TMapWithKeysValue>
mapWithKeys(callable $callback)

Run an associative map over each of the items.

TFlatMapValue>
flatMap(callable $callback)

Map a collection and flatten the result by a single level.

TMapIntoValue>
mapInto(string $class)

Map the values into a new class.

merge(mixed $items)

Merge the collection with the given items.

mergeRecursive(mixed $items)

Recursively merge the collection with the given items.

combine(Arrayable|iterable $values)

Create a collection by using this collection for keys and another for its values.

union(mixed $items)

Union the collection with the given items.

mixed
min(callable|int|string|null $callback = null)

Get the min value of a given key.

mixed
max(callable|int|string|null $callback = null)

Get the max value of a given key.

nth(int $step, int $offset = 0)

Create a new collection consisting of every n-th element.

only(mixed $keys)

Get the items with the specified keys.

forPage(int $page, int $perPage)

"Paginate" the collection by slicing it into a smaller collection.

TValue>>
partition(mixed $key, mixed $operator = null, mixed $value = null)

Partition the collection into two arrays using the given callback or key.

concat(iterable $source)

Push all of the given items onto the collection.

mixed
random(callable|int|string|null $number = null, bool $preserveKeys = false)

Get one or a specified number of items randomly from the collection.

mixed
reduce(callable $callback, mixed $initial = null)

Reduce the collection to a single value.

mixed
reduceInto(mixed $initial, callable $callback)

Reduce the collection to a single value by mutating an initial value.

array
reduceSpread(callable $callback, mixed ...$initial)

Reduce the collection to multiple aggregate values.

replace(mixed $items)

Replace the collection items with the given items.

replaceRecursive(mixed $items)

Recursively replace the collection items with the given items.

reverse()

Reverse items order.

mixed
search(mixed $value, bool $strict = false)

Search the collection for a given value and return the corresponding key if successful.

mixed
before(mixed $value, bool $strict = false)

Get the item before the given item.

mixed
after(mixed $value, bool $strict = false)

Get the item after the given item.

shuffle()

Shuffle the items in the collection.

sliding(int $size = 2, int $step = 1)

Create chunks representing a "sliding window" view of the items in the collection.

skip(int $count)

Skip the first {$count} items.

skipUntil(mixed $value)

Skip items in the collection until the given condition is met.

skipWhile(mixed $value)

Skip items in the collection while the given condition is met.

slice(int $offset, int|null $length = null)

Get a slice of items from the enumerable.

split(int $numberOfGroups)

Split a collection into a certain number of groups.

mixed
sole(callable|string|null $key = null, mixed $operator = null, mixed $value = null)

Get the first item in the collection, but only if exactly one item exists. Otherwise, throw an exception.

mixed
firstOrFail(callable|string|null $key = null, mixed $operator = null, mixed $value = null)

Get the first item in the collection but throw an exception if no matching items exist.

chunk(int $size)

Chunk the collection into chunks of the given size.

chunkWhile(callable $callback)

Chunk the collection into chunks with a callback.

splitIn(int $numberOfGroups)

Split a collection into a certain number of groups, and fill the first groups completely.

sort(callable|int|null $callback = null)

Sort through each item with a callback.

sortDesc(int $options = SORT_REGULAR)

Sort items in descending order.

sortBy(array|callable|int|string $callback, int $options = SORT_REGULAR, SortDirection|bool $descending = false)

Sort the collection using the given callback.

sortByDesc(array|callable|int|string $callback, int $options = SORT_REGULAR)

Sort the collection in descending order using the given callback.

sortKeys(int $options = SORT_REGULAR, SortDirection|bool $descending = false)

Sort the collection keys.

sortKeysDesc(int $options = SORT_REGULAR)

Sort the collection keys in descending order.

sortKeysUsing(callable $callback)

Sort the collection keys using a callback.

mixed
sum(callable|int|string|null $callback = null)

Get the sum of the given values.

take(int $limit)

Take the first or last {$limit} items.

takeUntil(mixed $value)

Take items in the collection until the given condition is met.

takeWhile(mixed $value)

Take items in the collection while the given condition is met.

tap(callable $callback)

Pass the collection to the given callback and then return it.

mixed
pipe(callable $callback)

Pass the enumerable to the given callback and return the result.

mixed
pipeInto(string $class)

Pass the collection into a new class.

mixed
pipeThrough(array $pipes)

Pass the collection through a series of callable pipes and return the result.

static<array-key, mixed>
pluck(Closure|string|int|array|null $value, Closure|string|int|array|null $key = null)

Get the values of a given key.

reject(mixed $callback = true)

Create a collection of all elements that do not pass a given truth test.

dot(int|float $depth = INF)

Flatten a multi-dimensional associative array with dots.

undot()

Convert a flatten "dot" notation array into an expanded array.

unique(callable|int|string|null $key = null, bool $strict = false)

Return only unique items from the collection array.

uniqueStrict(callable|string|null $key = null)

Return only unique items from the collection array using strict comparison.

values()

Reset the keys on the underlying array.

TPadValue|TValue>
pad(int $size, mixed $value)

Pad collection to the specified length with a value.

getIterator()

Get the values iterator.

int
count()

Count the number of items in the collection.

static<array-key, int>
countBy(callable|string|null $countBy = null)

Count the number of items in the collection by a field or using a callback.

TValue|TZipValue>>
zip(Arrayable|iterable ...$items)

Zip the collection together with one or more arrays.

collect()

Collect the values into a collection.

mixed
jsonSerialize()

Convert the object into something JSON serializable.

string
toPrettyJson(int $options = 0)

Get the collection of items as pretty print formatted JSON.

getCachingIterator(int $flags = CachingIterator::CALL_TOSTRING)

Get a CachingIterator instance.

string
__toString()

Convert the collection to its string representation.

escapeWhenCastingToString(bool $escape = true)

Indicate that the model's string representation should be escaped when __toString is invoked.

static void
proxy(string $method)

Add a method to the list of proxied methods.

mixed
__get(string $key)

Dynamically access collection proxies.

Details

at line 1111
array toArray()

Get the collection of items as a plain array.

Return Value

array

at line 1121
string toJson(int $options = 0)

Get the collection of items as JSON.

Parameters

int $options

Return Value

string

at line 39
static Enumerable make(Arrayable|iterable|null $items = [])

Create a new collection instance if the value isn't one already.

Parameters

Arrayable|iterable|null $items

Return Value

Enumerable

at line 49
static Enumerable times(int $number, callable|null $callback = null)

Create a new instance by invoking the callback a given amount of times.

Parameters

int $number
callable|null $callback

Return Value

Enumerable

at line 56
static Enumerable range(int $from, int $to, int $step = 1)

Create a collection with the given range.

Parameters

int $from
int $to
int $step

Return Value

Enumerable

at line 66
static Enumerable wrap(mixed $value)

Wrap the given value in a collection if applicable.

Parameters

mixed $value

Return Value

Enumerable

at line 71
static mixed unwrap(mixed $value)

Get the underlying items from the given collection if applicable.

Parameters

mixed $value

Return Value

mixed

at line 76
static Enumerable empty()

Create a new instance with no items.

Return Value

Enumerable

at line 83
array all()

Get all items in the enumerable.

Return Value

array

at line 90
float|int|null average(callable|string|null $callback = null)

Alias for the "avg" method.

Parameters

callable|string|null $callback

Return Value

float|int|null

at line 97
float|int|null median(string|array|null $key = null)

Get the median of a given key.

Parameters

string|array|null $key

Return Value

float|int|null

at line 105
array|null mode(string|array|null $key = null)

Get the mode of a given key.

Parameters

string|array|null $key

Return Value

array|null

at line 112
static<int, mixed> collapse()

Collapse the items into a single enumerable.

Return Value

static<int, mixed>

at line 119
bool some(mixed $key, mixed $operator = null, mixed $value = null)

Alias for the "contains" method.

Parameters

mixed $key
mixed $operator
mixed $value

Return Value

bool

at line 127
bool containsStrict(mixed $key, mixed $value = null)

Determine if an item exists, using strict comparison.

Parameters

mixed $key
mixed $value

Return Value

bool

at line 134
float|int|null avg(callable|int|string|null $callback = null)

Get the average value of a given key.

Parameters

callable|int|string|null $callback

Return Value

float|int|null

at line 141
bool contains(mixed $key, mixed $operator = null, mixed $value = null)

Determine if an item exists in the enumerable.

Parameters

mixed $key
mixed $operator
mixed $value

Return Value

bool

at line 146
bool doesntContain(mixed $key, mixed $operator = null, mixed $value = null)

Determine if an item is not contained in the collection.

Parameters

mixed $key
mixed $operator
mixed $value

Return Value

bool

at line 157
Enumerable crossJoin(Arrayable|iterable ...$lists)

Cross join with the given lists, returning all possible permutations.

Parameters

Arrayable|iterable ...$lists

Return Value

Enumerable

at line 162
never dd(mixed ...$args)

Dump the collection and end the script.

Parameters

mixed ...$args

Return Value

never

at line 167
Enumerable dump(mixed ...$args)

Dump the collection.

Parameters

mixed ...$args

Return Value

Enumerable

at line 174
Enumerable diff(mixed $items)

Get the items that are not present in the given items.

Parameters

mixed $items

Return Value

Enumerable

at line 182
Enumerable diffUsing(mixed $items, callable $callback)

Get the items that are not present in the given items, using the callback.

Parameters

mixed $items
callable $callback

Return Value

Enumerable

at line 189
Enumerable diffAssoc(Arrayable|iterable $items)

Get the items whose keys and values are not present in the given items.

Parameters

Arrayable|iterable $items

Return Value

Enumerable

at line 197
Enumerable diffAssocUsing(Arrayable|iterable $items, callable $callback)

Get the items whose keys and values are not present in the given items, using the callback.

Parameters

Arrayable|iterable $items
callable $callback

Return Value

Enumerable

at line 204
Enumerable diffKeys(Arrayable|iterable $items)

Get the items whose keys are not present in the given items.

Parameters

Arrayable|iterable $items

Return Value

Enumerable

at line 212
Enumerable diffKeysUsing(Arrayable|iterable $items, callable $callback)

Get the items whose keys are not present in the given items, using the callback.

Parameters

Arrayable|iterable $items
callable $callback

Return Value

Enumerable

at line 219
Enumerable duplicates(callable|string|null $callback = null, bool $strict = false)

Retrieve duplicate items.

Parameters

callable|string|null $callback
bool $strict

Return Value

Enumerable

at line 226
Enumerable duplicatesStrict(callable|string|null $callback = null)

Retrieve duplicate items using strict comparison.

Parameters

callable|string|null $callback

Return Value

Enumerable

at line 233
Enumerable each(callable $callback)

Execute a callback over each item.

Parameters

callable $callback

Return Value

Enumerable

at line 238
Enumerable eachSpread(callable $callback)

Execute a callback over each nested chunk of items.

Parameters

callable $callback

Return Value

Enumerable

at line 245
bool every(mixed $key, mixed $operator = null, mixed $value = null)

Determine if all items pass the given truth test.

Parameters

mixed $key
mixed $operator
mixed $value

Return Value

bool

at line 252
Enumerable except(mixed $keys)

Get all items except for those with the specified keys.

Parameters

mixed $keys

Return Value

Enumerable

at line 259
Enumerable filter(callable|null $callback = null)

Run a filter over each of the items.

Parameters

callable|null $callback

Return Value

Enumerable

at line 270
mixed when(mixed $value, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

Parameters

mixed $value
callable|null $callback
callable|null $default

Return Value

mixed

at line 281
mixed whenEmpty(callable $callback, callable|null $default = null)

Apply the callback if the collection is empty.

Parameters

callable $callback
callable|null $default

Return Value

mixed

at line 292
mixed whenNotEmpty(callable $callback, callable|null $default = null)

Apply the callback if the collection is not empty.

Parameters

callable $callback
callable|null $default

Return Value

mixed

at line 303
mixed unless(mixed $value, callable $callback, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

Parameters

mixed $value
callable $callback
callable|null $default

Return Value

mixed

at line 314
mixed unlessEmpty(callable $callback, callable|null $default = null)

Apply the callback unless the collection is empty.

Parameters

callable $callback
callable|null $default

Return Value

mixed

at line 325
mixed unlessNotEmpty(callable $callback, callable|null $default = null)

Apply the callback unless the collection is not empty.

Parameters

callable $callback
callable|null $default

Return Value

mixed

at line 330
Enumerable where(callable|string|null $key, mixed $operator = null, mixed $value = null)

Filter items by the given key value pair.

Parameters

callable|string|null $key
mixed $operator
mixed $value

Return Value

Enumerable

at line 335
Enumerable whereNull(string|null $key = null)

Filter items where the value for the given key is null.

Parameters

string|null $key

Return Value

Enumerable

at line 340
Enumerable whereNotNull(string|null $key = null)

Filter items where the value for the given key is not null.

Parameters

string|null $key

Return Value

Enumerable

at line 345
Enumerable whereStrict(callable|string|null $key, mixed $value)

Filter items by the given key value pair using strict comparison.

Parameters

callable|string|null $key
mixed $value

Return Value

Enumerable

at line 350
Enumerable whereIn(string $key, Arrayable|iterable $values, bool $strict = false)

Filter items by the given key value pair.

Parameters

string $key
Arrayable|iterable $values
bool $strict

Return Value

Enumerable

at line 355
Enumerable whereInStrict(string $key, Arrayable|iterable $values)

Filter items by the given key value pair using strict comparison.

Parameters

string $key
Arrayable|iterable $values

Return Value

Enumerable

at line 360
Enumerable whereBetween(string $key, Arrayable|iterable $values)

Filter items such that the value of the given key is between the given values.

Parameters

string $key
Arrayable|iterable $values

Return Value

Enumerable

at line 365
Enumerable whereNotBetween(string $key, Arrayable|iterable $values)

Filter items such that the value of the given key is not between the given values.

Parameters

string $key
Arrayable|iterable $values

Return Value

Enumerable

at line 370
Enumerable whereNotIn(string $key, Arrayable|iterable $values, bool $strict = false)

Filter items by the given key value pair.

Parameters

string $key
Arrayable|iterable $values
bool $strict

Return Value

Enumerable

at line 375
Enumerable whereNotInStrict(string $key, Arrayable|iterable $values)

Filter items by the given key value pair using strict comparison.

Parameters

string $key
Arrayable|iterable $values

Return Value

Enumerable

at line 385
Enumerable whereInstanceOf(string|array $type)

Filter the items, removing any items that don't match the given type(s).

Parameters

string|array $type

Return Value

Enumerable

at line 396
mixed first(callable|null $callback = null, mixed $default = null)

Get the first item from the enumerable passing the given truth test.

Parameters

callable|null $callback
mixed $default

Return Value

mixed

at line 403
mixed firstWhere(callable|string $key, mixed $operator = null, mixed $value = null)

Get the first item by the given key value pair.

Parameters

callable|string $key
mixed $operator
mixed $value

Return Value

mixed

at line 410
static<int, mixed> flatten(int|float $depth = INF)

Get a flattened array of the items in the collection.

Parameters

int|float $depth

Return Value

static<int, mixed>

at line 418
TKey> flip()

Flip the values with their keys.

Return Value

TKey>

at line 429
mixed get(mixed $key, mixed $default = null)

Get an item from the collection by key.

Parameters

mixed $key
mixed $default

Return Value

mixed

at line 439
Enumerable groupBy(callable|array|string $groupBy, bool $preserveKeys = false)

Group an associative array by a field or using a callback.

Parameters

callable|array|string $groupBy
bool $preserveKeys

Return Value

Enumerable

at line 449
Enumerable keyBy(callable|array|string $keyBy)

Key an associative array by a field or using a callback.

Parameters

callable|array|string $keyBy

Return Value

Enumerable

at line 456
bool has(mixed $key)

Determine if an item exists in the collection by key.

Parameters

mixed $key

Return Value

bool

at line 461
bool hasAny(mixed $key)

Determine if any of the keys exist in the collection.

Parameters

mixed $key

Return Value

bool

at line 468
string implode(callable|string|null $value, string|null $glue = null)

Concatenate values of a given key as a string.

Parameters

callable|string|null $value
string|null $glue

Return Value

string

at line 475
Enumerable intersect(mixed $items)

Intersect the collection with the given items.

Parameters

mixed $items

Return Value

Enumerable

at line 483
Enumerable intersectUsing(mixed $items, callable $callback)

Intersect the collection with the given items, using the callback.

Parameters

mixed $items
callable $callback

Return Value

Enumerable

at line 490
Enumerable intersectAssoc(mixed $items)

Intersect the collection with the given items with additional index check.

Parameters

mixed $items

Return Value

Enumerable

at line 498
Enumerable intersectAssocUsing(mixed $items, callable $callback)

Intersect the collection with the given items with additional index check, using the callback.

Parameters

mixed $items
callable $callback

Return Value

Enumerable

at line 505
Enumerable intersectByKeys(mixed $items)

Intersect the collection with the given items by key.

Parameters

mixed $items

Return Value

Enumerable

at line 510
bool isEmpty()

Determine if the collection is empty or not.

Return Value

bool

at line 515
bool isNotEmpty()

Determine if the collection is not empty.

Return Value

bool

at line 524
bool hasSole(callable|string|null $key = null, mixed $operator = null, mixed $value = null)

Determine if the collection contains a single item, optionally matching the given criteria.

Parameters

callable|string|null $key
mixed $operator
mixed $value

Return Value

bool

at line 531
bool hasMany(callable|string|null $key = null, mixed $operator = null, mixed $value = null)

Determine if the collection contains multiple items, optionally matching the given criteria.

Parameters

callable|string|null $key
mixed $operator
mixed $value

Return Value

bool

at line 536
string join(string $glue, string $finalGlue = '')

Join all items from the collection using a string. The final items can use a separate glue string.

Parameters

string $glue
string $finalGlue

Return Value

string

at line 543
TKey> keys()

Get the keys of the collection items.

Return Value

TKey>

at line 554
mixed last(callable|null $callback = null, mixed $default = null)

Get the last item from the collection.

Parameters

callable|null $callback
mixed $default

Return Value

mixed

at line 564
TMapValue> map(callable $callback)

Run a map over each of the items.

Parameters

callable $callback

Return Value

TMapValue>

at line 569
Enumerable mapSpread(callable $callback)

Run a map over each nested chunk of items.

Parameters

callable $callback

Return Value

Enumerable

at line 582
Enumerable mapToDictionary(callable $callback)

Run a dictionary map over the items.

The callback should return an associative array with a single key/value pair.

Parameters

callable $callback

Return Value

Enumerable

at line 595
Enumerable mapToGroups(callable $callback)

Run a grouping map over the items.

The callback should return an associative array with a single key/value pair.

Parameters

callable $callback

Return Value

Enumerable

at line 608
TMapWithKeysValue> mapWithKeys(callable $callback)

Run an associative map over each of the items.

The callback should return an associative array with a single key/value pair.

Parameters

callable $callback

Return Value

TMapWithKeysValue>

at line 622
TFlatMapValue> flatMap(callable $callback)

Map a collection and flatten the result by a single level.

No return type: Eloquent\Collection::collapse() returns base collection, which would violate : static when called on Eloquent\Collection.

Parameters

callable $callback

Return Value

TFlatMapValue>

at line 632
TMapIntoValue> mapInto(string $class)

Map the values into a new class.

Parameters

string $class

Return Value

TMapIntoValue>

at line 642
Enumerable merge(mixed $items)

Merge the collection with the given items.

Parameters

mixed $items

Return Value

Enumerable

at line 652
Enumerable mergeRecursive(mixed $items)

Recursively merge the collection with the given items.

Parameters

mixed $items

Return Value

Enumerable

at line 663
Enumerable combine(Arrayable|iterable $values)

Create a collection by using this collection for keys and another for its values.

Parameters

Arrayable|iterable $values

Return Value

Enumerable

at line 670
Enumerable union(mixed $items)

Union the collection with the given items.

Parameters

mixed $items

Return Value

Enumerable

at line 680
mixed min(callable|int|string|null $callback = null)

Get the min value of a given key.

Parameters

callable|int|string|null $callback

Return Value

mixed

at line 690
mixed max(callable|int|string|null $callback = null)

Get the max value of a given key.

Parameters

callable|int|string|null $callback

Return Value

mixed

at line 695
Enumerable nth(int $step, int $offset = 0)

Create a new collection consisting of every n-th element.

Parameters

int $step
int $offset

Return Value

Enumerable

at line 702
Enumerable only(mixed $keys)

Get the items with the specified keys.

Parameters

mixed $keys

Return Value

Enumerable

at line 707
Enumerable forPage(int $page, int $perPage)

"Paginate" the collection by slicing it into a smaller collection.

Parameters

int $page
int $perPage

Return Value

Enumerable

at line 715
TValue>> partition(mixed $key, mixed $operator = null, mixed $value = null)

Partition the collection into two arrays using the given callback or key.

Parameters

mixed $key
mixed $operator
mixed $value

Return Value

TValue>>

at line 726
Enumerable concat(iterable $source)

Push all of the given items onto the collection.

Parameters

iterable $source

Return Value

Enumerable

at line 735
mixed random(callable|int|string|null $number = null, bool $preserveKeys = false)

Get one or a specified number of items randomly from the collection.

Parameters

callable|int|string|null $number
bool $preserveKeys

Return Value

mixed

Exceptions

InvalidArgumentException

at line 747
mixed reduce(callable $callback, mixed $initial = null)

Reduce the collection to a single value.

Parameters

callable $callback
mixed $initial

Return Value

mixed

at line 758
mixed reduceInto(mixed $initial, callable $callback)

Reduce the collection to a single value by mutating an initial value.

Parameters

mixed $initial
callable $callback

Return Value

mixed

at line 765
array reduceSpread(callable $callback, mixed ...$initial)

Reduce the collection to multiple aggregate values.

Parameters

callable $callback
mixed ...$initial

Return Value

array

Exceptions

UnexpectedValueException

at line 772
Enumerable replace(mixed $items)

Replace the collection items with the given items.

Parameters

mixed $items

Return Value

Enumerable

at line 779
Enumerable replaceRecursive(mixed $items)

Recursively replace the collection items with the given items.

Parameters

mixed $items

Return Value

Enumerable

at line 784
Enumerable reverse()

Reverse items order.

Return Value

Enumerable

Search the collection for a given value and return the corresponding key if successful.

Parameters

mixed $value
bool $strict

Return Value

mixed

at line 800
mixed before(mixed $value, bool $strict = false)

Get the item before the given item.

Parameters

mixed $value
bool $strict

Return Value

mixed

at line 808
mixed after(mixed $value, bool $strict = false)

Get the item after the given item.

Parameters

mixed $value
bool $strict

Return Value

mixed

at line 813
Enumerable shuffle()

Shuffle the items in the collection.

Return Value

Enumerable

at line 820
Enumerable sliding(int $size = 2, int $step = 1)

Create chunks representing a "sliding window" view of the items in the collection.

Parameters

int $size
int $step

Return Value

Enumerable

at line 825
Enumerable skip(int $count)

Skip the first {$count} items.

Parameters

int $count

Return Value

Enumerable

at line 832
Enumerable skipUntil(mixed $value)

Skip items in the collection until the given condition is met.

Parameters

mixed $value

Return Value

Enumerable

at line 839
Enumerable skipWhile(mixed $value)

Skip items in the collection while the given condition is met.

Parameters

mixed $value

Return Value

Enumerable

at line 844
Enumerable slice(int $offset, int|null $length = null)

Get a slice of items from the enumerable.

Parameters

int $offset
int|null $length

Return Value

Enumerable

at line 851
Enumerable split(int $numberOfGroups)

Split a collection into a certain number of groups.

Parameters

int $numberOfGroups

Return Value

Enumerable

at line 862
mixed sole(callable|string|null $key = null, mixed $operator = null, mixed $value = null)

Get the first item in the collection, but only if exactly one item exists. Otherwise, throw an exception.

Parameters

callable|string|null $key
mixed $operator
mixed $value

Return Value

mixed

Exceptions

ItemNotFoundException
MultipleItemsFoundException

at line 872
mixed firstOrFail(callable|string|null $key = null, mixed $operator = null, mixed $value = null)

Get the first item in the collection but throw an exception if no matching items exist.

Parameters

callable|string|null $key
mixed $operator
mixed $value

Return Value

mixed

Exceptions

ItemNotFoundException

at line 879
Enumerable chunk(int $size)

Chunk the collection into chunks of the given size.

Parameters

int $size

Return Value

Enumerable

at line 887
Enumerable chunkWhile(callable $callback)

Chunk the collection into chunks with a callback.

Parameters

callable $callback

Return Value

Enumerable

at line 894
Enumerable splitIn(int $numberOfGroups)

Split a collection into a certain number of groups, and fill the first groups completely.

Parameters

int $numberOfGroups

Return Value

Enumerable

at line 901
Enumerable sort(callable|int|null $callback = null)

Sort through each item with a callback.

Parameters

callable|int|null $callback

Return Value

Enumerable

at line 908
Enumerable sortDesc(int $options = SORT_REGULAR)

Sort items in descending order.

Parameters

int $options

Return Value

Enumerable

at line 916
Enumerable sortBy(array|callable|int|string $callback, int $options = SORT_REGULAR, SortDirection|bool $descending = false)

Sort the collection using the given callback.

Parameters

array|callable|int|string $callback
int $options
SortDirection|bool $descending

Return Value

Enumerable

at line 924
Enumerable sortByDesc(array|callable|int|string $callback, int $options = SORT_REGULAR)

Sort the collection in descending order using the given callback.

Parameters

array|callable|int|string $callback
int $options

Return Value

Enumerable

at line 931
Enumerable sortKeys(int $options = SORT_REGULAR, SortDirection|bool $descending = false)

Sort the collection keys.

Parameters

int $options
SortDirection|bool $descending

Return Value

Enumerable

at line 938
Enumerable sortKeysDesc(int $options = SORT_REGULAR)

Sort the collection keys in descending order.

Parameters

int $options

Return Value

Enumerable

at line 945
Enumerable sortKeysUsing(callable $callback)

Sort the collection keys using a callback.

Parameters

callable $callback

Return Value

Enumerable

at line 955
mixed sum(callable|int|string|null $callback = null)

Get the sum of the given values.

Parameters

callable|int|string|null $callback

Return Value

mixed

at line 960
Enumerable take(int $limit)

Take the first or last {$limit} items.

Parameters

int $limit

Return Value

Enumerable

at line 967
Enumerable takeUntil(mixed $value)

Take items in the collection until the given condition is met.

Parameters

mixed $value

Return Value

Enumerable

at line 974
Enumerable takeWhile(mixed $value)

Take items in the collection while the given condition is met.

Parameters

mixed $value

Return Value

Enumerable

at line 981
Enumerable tap(callable $callback)

Pass the collection to the given callback and then return it.

Parameters

callable $callback

Return Value

Enumerable

at line 991
mixed pipe(callable $callback)

Pass the enumerable to the given callback and return the result.

Parameters

callable $callback

Return Value

mixed

at line 1001
mixed pipeInto(string $class)

Pass the collection into a new class.

Parameters

string $class

Return Value

mixed

at line 1008
mixed pipeThrough(array $pipes)

Pass the collection through a series of callable pipes and return the result.

Parameters

array $pipes

Return Value

mixed

at line 1016
static<array-key, mixed> pluck(Closure|string|int|array|null $value, Closure|string|int|array|null $key = null)

Get the values of a given key.

Parameters

Closure|string|int|array|null $value
Closure|string|int|array|null $key

Return Value

static<array-key, mixed>

at line 1023
Enumerable reject(mixed $callback = true)

Create a collection of all elements that do not pass a given truth test.

Parameters

mixed $callback

Return Value

Enumerable

at line 1028
Enumerable dot(int|float $depth = INF)

Flatten a multi-dimensional associative array with dots.

Parameters

int|float $depth

Return Value

Enumerable

at line 1033
Enumerable undot()

Convert a flatten "dot" notation array into an expanded array.

Return Value

Enumerable

at line 1040
Enumerable unique(callable|int|string|null $key = null, bool $strict = false)

Return only unique items from the collection array.

Parameters

callable|int|string|null $key
bool $strict

Return Value

Enumerable

at line 1047
Enumerable uniqueStrict(callable|string|null $key = null)

Return only unique items from the collection array using strict comparison.

Parameters

callable|string|null $key

Return Value

Enumerable

at line 1054
Enumerable values()

Reset the keys on the underlying array.

Return Value

Enumerable

at line 1064
TPadValue|TValue> pad(int $size, mixed $value)

Pad collection to the specified length with a value.

Parameters

int $size
mixed $value

Return Value

TPadValue|TValue>

at line 1071
Traversable getIterator()

Get the values iterator.

Return Value

Traversable

at line 1076
int count()

Count the number of items in the collection.

Return Value

int

at line 1084
static<array-key, int> countBy(callable|string|null $countBy = null)

Count the number of items in the collection by a field or using a callback.

Parameters

callable|string|null $countBy

Return Value

static<array-key, int>

at line 1097
TValue|TZipValue>> zip(Arrayable|iterable ...$items)

Zip the collection together with one or more arrays.

e.g. new Collection([1, 2, 3])->zip([4, 5, 6]); => [[1, 4], [2, 5], [3, 6]]

Parameters

Arrayable|iterable ...$items

Return Value

TValue|TZipValue>>

at line 1104
Collection collect()

Collect the values into a collection.

Return Value

Collection

at line 1116
mixed jsonSerialize()

Convert the object into something JSON serializable.

Return Value

mixed

at line 1126
string toPrettyJson(int $options = 0)

Get the collection of items as pretty print formatted JSON.

Parameters

int $options

Return Value

string

at line 1131
CachingIterator getCachingIterator(int $flags = CachingIterator::CALL_TOSTRING)

Get a CachingIterator instance.

Parameters

int $flags

Return Value

CachingIterator

at line 1136
string __toString()

Convert the collection to its string representation.

Return Value

string

at line 1141
Enumerable escapeWhenCastingToString(bool $escape = true)

Indicate that the model's string representation should be escaped when __toString is invoked.

Parameters

bool $escape

Return Value

Enumerable

at line 1150
static void proxy(string $method)

Add a method to the list of proxied methods.

Boot or tests only. The method is registered on a worker-wide static and applies to every subsequent collection access; per-request use races across coroutines.

Parameters

string $method

Return Value

void

at line 1157
mixed __get(string $key)

Dynamically access collection proxies.

Parameters

string $key

Return Value

mixed

Exceptions

Exception