class Collection extends Collection implements QueueableCollection

Traits

Properties

protected bool $escapeWhenCastingToString

Indicates that the object's string representation should be escaped when __toString is invoked.

from  EnumeratesValues
static protected array<int, string> $proxies

The methods that can be proxied.

from  EnumeratesValues
TValue, static> read-only $average from  EnumeratesValues
TValue, static> read-only $avg from  EnumeratesValues
TValue, static> read-only $contains from  EnumeratesValues
TValue, static> read-only $doesntContain from  EnumeratesValues
TValue, static> read-only $each from  EnumeratesValues
TValue, static> read-only $every from  EnumeratesValues
TValue, static> read-only $filter from  EnumeratesValues
TValue, static> read-only $first from  EnumeratesValues
TValue, static> read-only $flatMap from  EnumeratesValues
TValue, static> read-only $groupBy from  EnumeratesValues
TValue, static> read-only $hasMany from  EnumeratesValues
TValue, static> read-only $hasSole from  EnumeratesValues
TValue, static> read-only $keyBy from  EnumeratesValues
TValue, static> read-only $last from  EnumeratesValues
TValue, static> read-only $map from  EnumeratesValues
TValue, static> read-only $max from  EnumeratesValues
TValue, static> read-only $min from  EnumeratesValues
TValue, static> read-only $partition from  EnumeratesValues
TValue, static> read-only $percentage from  EnumeratesValues
TValue, static> read-only $reject from  EnumeratesValues
TValue, static> read-only $skipUntil from  EnumeratesValues
TValue, static> read-only $skipWhile from  EnumeratesValues
TValue, static> read-only $sole from  EnumeratesValues
TValue, static> read-only $some from  EnumeratesValues
TValue, static> read-only $sortBy from  EnumeratesValues
TValue, static> read-only $sortByDesc from  EnumeratesValues
TValue, static> read-only $sum from  EnumeratesValues
TValue, static> read-only $takeUntil from  EnumeratesValues
TValue, static> read-only $takeWhile from  EnumeratesValues
TValue, static> read-only $unique from  EnumeratesValues
TValue, static> read-only $unless from  EnumeratesValues
TValue, static> read-only $when from  EnumeratesValues
static protected array $macros

The registered string macros.

from  Macroable
protected TValue> $items

The items contained in the collection.

from  Collection

Methods

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

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

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

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

make(mixed $items = [], mixed ...$args)

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

wrap(mixed $value, mixed ...$args)

Wrap the given value in a collection if applicable.

static mixed
unwrap(mixed $value)

Get the underlying items from the given collection if applicable.

empty(mixed ...$args)

Create a new instance with no items.

times(int $number, callable|null $callback = null, mixed ...$args)

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

fromJson(string $json, int $depth = 513, int $flags = 0, mixed ...$args)

Create a new collection by decoding a JSON string.

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

Get the average value of a given key.

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

Alias for the "avg" method.

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

Alias for the "contains" method.

never
dd(mixed ...$args)

Dump the given arguments and terminate execution.

dump(mixed ...$args)

Dump the items.

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.

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

Get the first item by the given key value pair.

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.

mixed
value(string $key, mixed $default = null)

Get a single key's value from the first matching item in the collection.

ensure(string|array $type)

Ensure that every item in the collection is of the expected type.

bool
isNotEmpty()

Determine if the collection is not empty.

mapSpread(callable $callback)

Run a map over each nested chunk of items.

mapToGroups(callable $callback)

Run a grouping map over the items.

flatMap(callable $callback)

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

mapInto(string $class)

Map the values into a new class.

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.

forPage(int $page, int $perPage)

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

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

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

float|null
percentage(callable $callback, int $precision = 2)

Calculate the percentage of items that pass a given truth test.

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

Get the sum of the given values.

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
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
pipe(callable $callback)

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

mixed
pipeInto(string $class)

Pass the collection into a new class.

mixed
pipeThrough(array $callbacks)

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

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.

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

Reduce an associative collection to a single value.

reject(mixed $callback = true)

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

chunkBy(callable|string $key)

Chunk the collection into chunks by comparing adjacent values using the given key or callback.

tap(callable $callback)

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

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

Return only unique items from the collection.

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

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

collect()

Collect the values into a collection.

array
toArray()

Get the collection of items as a plain array.

array
jsonSerialize()

Convert the object into something JSON serializable.

string
toJson(int $options = 0)

Get the collection of items as JSON.

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.

static void
flushProxies()

Flush the registered proxies, restoring the default list.

mixed
__get(string $key)

Dynamically access collection proxies.

array
getArrayableItems(mixed $items)

Results array of items from Collection or Arrayable.

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

Get an operator checker callback.

bool
useAsCallable(mixed $value)

Determine if the given value is callable, but not a string.

callable
valueRetriever(callable|int|string|null $value)

Get a value retrieving callback.

equality(mixed $value)

Make a function to check an item's equality.

negate(Closure $callback)

Make a function using another function, by negating its result.

identity()

Make a function that returns what's passed to it.

static void
macro(string $name, callable|object $macro)

Register a custom macro.

static void
mixin(object $mixin, bool $replace = true)

Mix another object into the class.

static bool
hasMacro(string $name)

Check if macro is registered.

static void
flushMacros()

Flush the existing macros.

static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Dynamically handle calls to the class.

toResourceCollection(string|null $resourceClass = null)

Create a new resource collection instance for the given resource.

guessResourceCollection()

Guess the resource collection for the items.

string|null
resolveResourceFromAttribute(string $class)

Get the resource class from the class attribute.

string|null
resolveResourceCollectionFromAttribute(string $class)

Get the resource collection class from the class attribute.

__construct(null|TValue>>|TValue> $items = [])

Create a new collection.

newInstance(mixed $items = [])

Create a new instance of the collection.

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

Create a collection with the given range.

array
all()

Get all of the items in the collection.

lazy()

Get a lazy collection for the items in this collection.

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.

collapse()

Collapse the collection of items into a single array.

collapseWithKeys()

Collapse the collection of items into a single array while preserving its keys.

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

Determine if a key exists in the collection.

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

Determine if an item exists, using strict comparison.

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

Determine if a key does not exist in the collection.

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

Determine if an item is not contained in the enumerable, using strict comparison.

crossJoin(Arrayable|iterable ...$lists)

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

diff(mixed $items)

Diff the collection with the given items.

diffUsing(mixed $items, callable $callback)

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

diffAssoc(Arrayable|iterable $items)

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

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

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

diffKeys(Arrayable|iterable $items)

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

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

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

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

Retrieve duplicate items from the collection.

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

Retrieve duplicate items from the collection using strict comparison.

callable
duplicateComparator(bool $strict)

Get the comparison function to detect duplicates.

except(mixed $keys)

Return all models in the collection except the models with specified keys.

filter(callable|null $callback = null)

Run a filter over each of the items.

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

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

flatten(int|float $depth = INF)

Get a flattened array of the items in the collection.

flip()

Flip the items in the collection.

forget(mixed $keys)

Remove an item from the collection by key.

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

Get an item from the collection by key.

mixed
getOrPut(mixed $key, mixed $value)

Get an item from the collection by key or add it to collection if it does not exist.

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.

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

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

keys()

Get the keys of the collection items.

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

Get the last item from the collection.

pluck(Closure|string|int|array|null $value, Closure|string|int|array|null $key = null)

Get the values of a given key.

map(callable $callback)

Run a map over each of the items.

mapToDictionary(callable $callback)

Run a dictionary map over the items.

mapWithKeys(callable $callback)

Run an associative map over each of the items.

merge(mixed $items)

Merge the collection with the given items.

mergeRecursive(mixed $items)

Recursively merge the collection with the given items.

multiply(int $multiplier)

Multiply the items in the collection by the multiplier.

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.

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

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

only(mixed $keys)

Return only the models from the collection with the specified keys.

select(mixed $keys)

Select specific values from the items within the collection.

mixed
pop(int $count = 1)

Get and remove the last N items from the collection.

prepend(mixed $value, mixed $key = null)

Push an item onto the beginning of the collection.

push(mixed ...$values)

Push one or more items onto the end of the collection.

unshift(mixed ...$values)

Prepend one or more items to the beginning of the collection.

concat(iterable $source)

Push all of the given items onto the collection.

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

Get and remove an item from the collection.

put(mixed $key, mixed $value)

Put an item in the collection by key.

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

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

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.

mixed
shift(int $count = 1)

Get and remove the first N items from the collection.

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)

Slice the underlying collection array.

split(int $numberOfGroups)

Split a collection into a certain number of groups.

splitIn(int $numberOfGroups)

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

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.

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.

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, bool $preserveKeys = true)

Chunk the collection into chunks of the given size.

chunkWhile(callable $callback)

Chunk the collection into chunks with a callback.

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.

sortByMany(array $comparisons = [], int $options = SORT_REGULAR)

Sort the collection using multiple comparisons.

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.

splice(int $offset, int|null $length = null, mixed $replacement = [])

Splice a portion of the underlying collection array.

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.

transform(callable $callback)

Transform each item in the collection using a callback.

dot(int|float $depth = INF)

Flatten a multi-dimensional associative array with dots.

undot()

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

values()

Reset the keys on the underlying array.

zip(Arrayable|iterable ...$items)

Zip the collection together with one or more arrays.

pad(int $size, mixed $value)

Pad collection to the specified length with a value.

getIterator()

Get an iterator for the items.

int
count()

Count the number of items in the collection.

countBy(callable|string|null $countBy = null)

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

add(mixed $item)

Add an item to the collection.

toBase()

Get a base Support collection instance from this collection.

bool
offsetExists(TKey $offset)

Determine if an item exists at an offset.

mixed
offsetGet(TKey $offset)

Get an item at a given offset.

void
offsetSet(null|TKey $offset, TValue $value)

Set the item at a given offset.

void
offsetUnset(TKey $offset)

Unset the item at a given offset.

static void
flushState()

Flush all static state.

int|string|null
getDictionaryKey(mixed $attribute)

Get a dictionary key attribute - casting it to a string if necessary.

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

Find a model in the collection by key.

findOrFail(mixed $key)

Find a model in the collection by key or throw an exception.

load(array|string $relations)

Load a set of relationships onto the collection.

loadAggregate(array|string $relations, Expression|string $column, string|null $function = null)

Load a set of aggregations over relationship's column onto the collection.

loadCount(array|string $relations)

Load a set of relationship counts onto the collection.

loadMax(array|string $relations, Expression|string $column)

Load a set of relationship's max column values onto the collection.

loadMin(array|string $relations, Expression|string $column)

Load a set of relationship's min column values onto the collection.

loadSum(array|string $relations, Expression|string $column)

Load a set of relationship's column summations onto the collection.

loadAvg(array|string $relations, Expression|string $column)

Load a set of relationship's average column values onto the collection.

loadExists(array|string $relations)

Load a set of related existences onto the collection.

loadMissing(array|string $relations)

Load a set of relationships onto the collection if they are not already eager loaded.

void
loadMissingRelationshipChain(array $tuples)

Load a relationship path for models of the given type if it is not already eager loaded.

void
loadMissingRelation(Collection $models, array $path)

Load a relationship path if it is not already eager loaded.

loadMorph(string $relation, array $relations)

Load a set of relationships onto the mixed relationship collection.

loadMorphCount(string $relation, array $relations)

Load a set of relationship counts onto the mixed relationship collection.

array
modelKeys()

Get the array of primary keys.

fresh(array|string $with = [])

Reload a fresh model instance from the database for all the entities.

makeHidden(array|string $attributes)

Make the given, typically visible, attributes hidden across the entire collection.

mergeHidden(array|string $attributes)

Merge the given, typically visible, attributes hidden across the entire collection.

setHidden(array $hidden)

Set the hidden attributes across the entire collection.

makeVisible(array|string $attributes)

Make the given, typically hidden, attributes visible across the entire collection.

mergeVisible(array|string $attributes)

Merge the given, typically hidden, attributes visible across the entire collection.

setVisible(array $visible)

Set the visible attributes across the entire collection.

append(array|string $attributes)

Append an attribute across the entire collection.

setAppends(array $appends)

Sets the appends on every element of the collection, overwriting the existing appends for each.

withoutAppends()

Remove appended properties from every element in the collection.

array
getDictionary(iterable|null $items = null)

Get a dictionary keyed by primary keys.

withRelationshipAutoloading()

Enable relationship autoloading for all models in this collection.

string|null
getQueueableClass()

Get the type of the entities being queued.

string
getQueueableModelClass(mixed $model)

Get the queueable class name for the given model.

array
getQueueableIds()

Get the identifiers for all of the entities.

array
getQueueableRelations()

Get the relationships of the entities being queued.

string|null
getQueueableConnection()

Get the connection of the entities being queued.

toQuery()

Get the Eloquent query builder from the collection.

Details

in Conditionable at line 23
mixed when(mixed $value = null, 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

in Conditionable at line 56
mixed unless(mixed $value = null, callable|null $callback = null, callable|null $default = null)

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

Parameters

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

Return Value

mixed

in EnumeratesValues at line 128
static EnumeratesValues make(mixed $items = [], mixed ...$args)

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

Parameters

mixed $items
mixed ...$args

Return Value

EnumeratesValues

in EnumeratesValues at line 141
static EnumeratesValues wrap(mixed $value, mixed ...$args)

Wrap the given value in a collection if applicable.

Parameters

mixed $value
mixed ...$args

Return Value

EnumeratesValues

in EnumeratesValues at line 158
static mixed unwrap(mixed $value)

Get the underlying items from the given collection if applicable.

Parameters

mixed $value

Return Value

mixed

in EnumeratesValues at line 166
static EnumeratesValues empty(mixed ...$args)

Create a new instance with no items.

Parameters

mixed ...$args

Return Value

EnumeratesValues

in EnumeratesValues at line 179
static Collection|EnumeratesValues times(int $number, callable|null $callback = null, mixed ...$args)

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

Parameters

int $number
callable|null $callback
mixed ...$args

Return Value

Collection|EnumeratesValues

in EnumeratesValues at line 195
static EnumeratesValues fromJson(string $json, int $depth = 513, int $flags = 0, mixed ...$args)

Create a new collection by decoding a JSON string.

Parameters

string $json
int $depth
int $flags
mixed ...$args

Return Value

EnumeratesValues

in EnumeratesValues at line 206
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

in EnumeratesValues at line 227
float|int|null average(callable|string|null $callback = null)

Alias for the "avg" method.

Parameters

callable|string|null $callback

Return Value

float|int|null

in EnumeratesValues at line 237
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

in EnumeratesValues at line 245
never dd(mixed ...$args)

Dump the given arguments and terminate execution.

Parameters

mixed ...$args

Return Value

never

in EnumeratesValues at line 255
EnumeratesValues dump(mixed ...$args)

Dump the items.

Parameters

mixed ...$args

Return Value

EnumeratesValues

in EnumeratesValues at line 268
EnumeratesValues each(callable $callback)

Execute a callback over each item.

Parameters

callable $callback

Return Value

EnumeratesValues

in EnumeratesValues at line 282
EnumeratesValues eachSpread(callable $callback)

Execute a callback over each nested chunk of items.

Parameters

callable $callback

Return Value

EnumeratesValues

in EnumeratesValues at line 294
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

in EnumeratesValues at line 316
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

in EnumeratesValues at line 326
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

in EnumeratesValues at line 347
mixed value(string $key, mixed $default = null)

Get a single key's value from the first matching item in the collection.

Parameters

string $key
mixed $default

Return Value

mixed

in EnumeratesValues at line 366
EnumeratesValues ensure(string|array $type)

Ensure that every item in the collection is of the expected type.

Parameters

string|array $type

Return Value

EnumeratesValues

Exceptions

UnexpectedValueException

in EnumeratesValues at line 395
bool isNotEmpty()

Determine if the collection is not empty.

Return Value

bool

in EnumeratesValues at line 405
Collection|EnumeratesValues mapSpread(callable $callback)

Run a map over each nested chunk of items.

Parameters

callable $callback

Return Value

Collection|EnumeratesValues

in EnumeratesValues at line 423
Collection|EnumeratesValues 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

Collection|EnumeratesValues

in EnumeratesValues at line 439
Collection|EnumeratesValues flatMap(callable $callback)

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

Parameters

callable $callback

Return Value

Collection|EnumeratesValues

in EnumeratesValues at line 452
Collection|EnumeratesValues mapInto(string $class)

Map the values into a new class.

Parameters

string $class

Return Value

Collection|EnumeratesValues

in EnumeratesValues at line 469
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

in EnumeratesValues at line 486
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

in EnumeratesValues at line 500
EnumeratesValues forPage(int $page, int $perPage)

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

Parameters

int $page
int $perPage

Return Value

EnumeratesValues

at line 912
Collection|EnumeratesValues 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

Collection|EnumeratesValues

in EnumeratesValues at line 530
float|null percentage(callable $callback, int $precision = 2)

Calculate the percentage of items that pass a given truth test.

Parameters

callable $callback
int $precision

Return Value

float|null

in EnumeratesValues at line 550
mixed sum(callable|int|string|null $callback = null)

Get the sum of the given values.

Parameters

callable|int|string|null $callback

Return Value

mixed

in EnumeratesValues at line 568
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

in EnumeratesValues at line 582
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

in EnumeratesValues at line 596
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

in EnumeratesValues at line 610
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

in EnumeratesValues at line 618
EnumeratesValues 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

EnumeratesValues

in EnumeratesValues at line 626
EnumeratesValues whereNull(string|null $key = null)

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

Parameters

string|null $key

Return Value

EnumeratesValues

in EnumeratesValues at line 634
EnumeratesValues whereNotNull(string|null $key = null)

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

Parameters

string|null $key

Return Value

EnumeratesValues

in EnumeratesValues at line 642
EnumeratesValues 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

EnumeratesValues

in EnumeratesValues at line 650
EnumeratesValues 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

EnumeratesValues

in EnumeratesValues at line 660
EnumeratesValues 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

EnumeratesValues

in EnumeratesValues at line 668
EnumeratesValues 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

EnumeratesValues

in EnumeratesValues at line 678
EnumeratesValues 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

EnumeratesValues

in EnumeratesValues at line 694
EnumeratesValues 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

EnumeratesValues

in EnumeratesValues at line 704
EnumeratesValues 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

EnumeratesValues

in EnumeratesValues at line 717
EnumeratesValues whereInstanceOf(string|array $type)

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

Parameters

string|array $type

Return Value

EnumeratesValues

in EnumeratesValues at line 744
mixed pipe(callable $callback)

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

Parameters

callable $callback

Return Value

mixed

in EnumeratesValues at line 757
mixed pipeInto(string $class)

Pass the collection into a new class.

Parameters

string $class

Return Value

mixed

in EnumeratesValues at line 767
mixed pipeThrough(array $callbacks)

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

Parameters

array $callbacks

Return Value

mixed

in EnumeratesValues at line 785
mixed reduce(callable $callback, mixed $initial = null)

Reduce the collection to a single value.

Parameters

callable $callback
mixed $initial

Return Value

mixed

in EnumeratesValues at line 805
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

in EnumeratesValues at line 819
array reduceSpread(callable $callback, mixed ...$initial)

Reduce the collection to multiple aggregate values.

Parameters

callable $callback
mixed ...$initial

Return Value

array

Exceptions

UnexpectedValueException

in EnumeratesValues at line 848
mixed reduceWithKeys(callable $callback, mixed $initial = null)

Reduce an associative collection to a single value.

Parameters

callable $callback
mixed $initial

Return Value

mixed

in EnumeratesValues at line 858
EnumeratesValues reject(mixed $callback = true)

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

Parameters

mixed $callback

Return Value

EnumeratesValues

in EnumeratesValues at line 875
EnumeratesValues chunkBy(callable|string $key)

Chunk the collection into chunks by comparing adjacent values using the given key or callback.

Parameters

callable|string $key

Return Value

EnumeratesValues

in EnumeratesValues at line 891
EnumeratesValues tap(callable $callback)

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

Parameters

callable $callback

Return Value

EnumeratesValues

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

Return only unique items from the collection.

Parameters

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

Return Value

Enumerable

in EnumeratesValues at line 923
EnumeratesValues uniqueStrict(callable|string|null $key = null)

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

Parameters

callable|string|null $key

Return Value

EnumeratesValues

in EnumeratesValues at line 933
Collection collect()

Collect the values into a collection.

Return Value

Collection

in EnumeratesValues at line 943
array toArray()

Get the collection of items as a plain array.

Return Value

array

in EnumeratesValues at line 953
array jsonSerialize()

Convert the object into something JSON serializable.

Return Value

array

in EnumeratesValues at line 971
string toJson(int $options = 0)

Get the collection of items as JSON.

Parameters

int $options

Return Value

string

Exceptions

JsonException

in EnumeratesValues at line 981
string toPrettyJson(int $options = 0)

Get the collection of items as pretty print formatted JSON.

Parameters

int $options

Return Value

string

Exceptions

JsonException

in EnumeratesValues at line 989
CachingIterator getCachingIterator(int $flags = CachingIterator::CALL_TOSTRING)

Get a CachingIterator instance.

Parameters

int $flags

Return Value

CachingIterator

in EnumeratesValues at line 998
string __toString()

Convert the collection to its string representation.

Return Value

string

in EnumeratesValues at line 1010
EnumeratesValues escapeWhenCastingToString(bool $escape = true)

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

Parameters

bool $escape

Return Value

EnumeratesValues

in EnumeratesValues at line 1023
static void proxy(string $method)

Add a method to the list of proxied methods.

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

in EnumeratesValues at line 1035
static void flushProxies()

Flush the registered proxies, restoring the default list.

Resets the worker-wide proxy registry; concurrent coroutines may resolve different proxies depending on timing.

Return Value

void

in EnumeratesValues at line 1046
mixed __get(string $key)

Dynamically access collection proxies.

Parameters

string $key

Return Value

mixed

Exceptions

Exception

in EnumeratesValues at line 1060
protected array getArrayableItems(mixed $items)

Results array of items from Collection or Arrayable.

Parameters

mixed $items

Return Value

array

in EnumeratesValues at line 1070
protected callable operatorForWhere(callable|string|null $key, mixed $operator = null, mixed $value = null)

Get an operator checker callback.

Parameters

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

Return Value

callable

in EnumeratesValues at line 1124
protected bool useAsCallable(mixed $value)

Determine if the given value is callable, but not a string.

Parameters

mixed $value

Return Value

bool

in EnumeratesValues at line 1132
protected callable valueRetriever(callable|int|string|null $value)

Get a value retrieving callback.

Parameters

callable|int|string|null $value

Return Value

callable

in EnumeratesValues at line 1146
protected Closure equality(mixed $value)

Make a function to check an item's equality.

Parameters

mixed $value

Return Value

Closure

in EnumeratesValues at line 1154
protected Closure negate(Closure $callback)

Make a function using another function, by negating its result.

Parameters

Closure $callback

Return Value

Closure

in EnumeratesValues at line 1164
protected Closure identity()

Make a function that returns what's passed to it.

Return Value

Closure

in Macroable at line 30
static void macro(string $name, callable|object $macro)

Register a custom macro.

Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.

Parameters

string $name
callable|object $macro

Return Value

void

in Macroable at line 44
static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

in Macroable at line 61
static bool hasMacro(string $name)

Check if macro is registered.

Parameters

string $name

Return Value

bool

in Macroable at line 72
static void flushMacros()

Flush the existing macros.

Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.

Return Value

void

in Macroable at line 83
static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in Macroable at line 108
mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

ResourceCollection toResourceCollection(string|null $resourceClass = null)

Create a new resource collection instance for the given resource.

Parameters

string|null $resourceClass

Return Value

ResourceCollection

Exceptions

Throwable

protected ResourceCollection guessResourceCollection()

Guess the resource collection for the items.

Return Value

ResourceCollection

Exceptions

Throwable

protected string|null resolveResourceFromAttribute(string $class)

Get the resource class from the class attribute.

Parameters

string $class

Return Value

string|null

protected string|null resolveResourceCollectionFromAttribute(string $class)

Get the resource collection class from the class attribute.

Parameters

string $class

Return Value

string|null

in Collection at line 54
__construct(null|TValue>>|TValue> $items = [])

Create a new collection.

Parameters

null|TValue>>|TValue> $items

in Collection at line 68
protected Collection newInstance(mixed $items = [])

Create a new instance of the collection.

Parameters

mixed $items

Return Value

Collection

in Collection at line 78
static Enumerable range(int $from, int $to, int $step = 1, mixed ...$args)

Create a collection with the given range.

Parameters

int $from
int $to
int $step
mixed ...$args

Return Value

Enumerable

in Collection at line 88
array all()

Get all of the items in the collection.

Return Value

array

in Collection at line 98
LazyCollection lazy()

Get a lazy collection for the items in this collection.

Return Value

LazyCollection

in Collection at line 108
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

in Collection at line 137
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 855
Collection|Enumerable collapse()

Collapse the collection of items into a single array.

Return Value

Collection|Enumerable

in Collection at line 187
Collection collapseWithKeys()

Collapse the collection of items into a single array while preserving its keys.

Return Value

Collection

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

Determine if a key exists in the collection.

Parameters

mixed $key
mixed $operator
mixed $value

Return Value

bool

in Collection at line 236
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 463
bool doesntContain(mixed $key, mixed $operator = null, mixed $value = null)

Determine if a key does not exist in the collection.

Parameters

mixed $key
mixed $operator
mixed $value

Return Value

bool

in Collection at line 260
bool doesntContainStrict(mixed $key, mixed $operator = null, mixed $value = null)

Determine if an item is not contained in the enumerable, using strict comparison.

Parameters

mixed $key
mixed $operator
mixed $value

Return Value

bool

in Collection at line 273
Enumerable crossJoin(Arrayable|iterable ...$lists)

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

Parameters

Arrayable|iterable ...$lists

Return Value

Enumerable

at line 603
Enumerable diff(mixed $items)

Diff the collection with the given items.

Parameters

mixed $items

Return Value

Enumerable

in Collection at line 297
Enumerable diffUsing(mixed $items, callable $callback)

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

Parameters

mixed $items
callable $callback

Return Value

Enumerable

in Collection at line 307
Enumerable diffAssoc(Arrayable|iterable $items)

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

Parameters

Arrayable|iterable $items

Return Value

Enumerable

in Collection at line 318
Enumerable diffAssocUsing(Arrayable|iterable $items, callable $callback)

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

Parameters

Arrayable|iterable $items
callable $callback

Return Value

Enumerable

in Collection at line 328
Enumerable diffKeys(Arrayable|iterable $items)

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

Parameters

Arrayable|iterable $items

Return Value

Enumerable

in Collection at line 339
Enumerable diffKeysUsing(Arrayable|iterable $items, callable $callback)

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

Parameters

Arrayable|iterable $items
callable $callback

Return Value

Enumerable

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

Retrieve duplicate items from the collection.

Parameters

callable|string|null $callback
bool $strict

Return Value

Collection|Enumerable

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

Retrieve duplicate items from the collection using strict comparison.

Parameters

callable|string|null $callback

Return Value

Collection|Enumerable

at line 984
protected callable duplicateComparator(bool $strict)

Get the comparison function to detect duplicates.

Parameters

bool $strict

Return Value

callable

at line 688
Enumerable except(mixed $keys)

Return all models in the collection except the models with specified keys.

Parameters

mixed $keys

Return Value

Enumerable

in Collection at line 426
Enumerable filter(callable|null $callback = null)

Run a filter over each of the items.

Parameters

callable|null $callback

Return Value

Enumerable

in Collection at line 444
mixed first(callable|null $callback = null, mixed $default = null)

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

Parameters

callable|null $callback
mixed $default

Return Value

mixed

at line 866
Collection|Enumerable flatten(int|float $depth = INF)

Get a flattened array of the items in the collection.

Parameters

int|float $depth

Return Value

Collection|Enumerable

at line 877
Collection|Enumerable flip()

Flip the items in the collection.

Return Value

Collection|Enumerable

in Collection at line 475
Collection forget(mixed $keys)

Remove an item from the collection by key.

Parameters

mixed $keys

Return Value

Collection

in Collection at line 493
mixed get(mixed $key, mixed $default = null)

Get an item from the collection by key.

Parameters

mixed $key
mixed $default

Return Value

mixed

in Collection at line 516
mixed getOrPut(mixed $key, mixed $value)

Get an item from the collection by key or add it to collection if it does not exist.

Parameters

mixed $key
mixed $value

Return Value

mixed

in Collection at line 542
Collection|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

Collection|Enumerable

in Collection at line 597
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

in Collection at line 628
bool has(mixed $key)

Determine if an item exists in the collection by key.

Parameters

mixed $key

Return Value

bool

in Collection at line 640
bool hasAny(mixed $key)

Determine if any of the keys exist in the collection.

Parameters

mixed $key

Return Value

bool

in Collection at line 656
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 626
Enumerable intersect(mixed $items)

Intersect the collection with the given items.

Parameters

mixed $items

Return Value

Enumerable

in Collection at line 687
Enumerable intersectUsing(mixed $items, callable $callback)

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

Parameters

mixed $items
callable $callback

Return Value

Enumerable

in Collection at line 697
Enumerable intersectAssoc(mixed $items)

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

Parameters

mixed $items

Return Value

Enumerable

in Collection at line 708
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

in Collection at line 718
Enumerable intersectByKeys(mixed $items)

Intersect the collection with the given items by key.

Parameters

mixed $items

Return Value

Enumerable

in Collection at line 735
bool isEmpty()

Determine if the collection is empty or not.

Return Value

bool

in Collection at line 745
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 888
Collection|Enumerable keys()

Get the keys of the collection items.

Return Value

Collection|Enumerable

in Collection at line 787
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 928
Collection|Enumerable 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

Collection|Enumerable

at line 512
Collection&Enumerable map(callable $callback)

Run a map over each of the items.

Parameters

callable $callback

Return Value

Collection&Enumerable

in Collection at line 831
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 532
Collection&Enumerable 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

Collection&Enumerable

at line 485
Enumerable merge(mixed $items)

Merge the collection with the given items.

Parameters

mixed $items

Return Value

Enumerable

in Collection at line 889
Enumerable mergeRecursive(mixed $items)

Recursively merge the collection with the given items.

Parameters

mixed $items

Return Value

Enumerable

in Collection at line 899
Collection multiply(int $multiplier)

Multiply the items in the collection by the multiplier.

Parameters

int $multiplier

Return Value

Collection

in Collection at line 918
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

in Collection at line 928
Enumerable union(mixed $items)

Union the collection with the given items.

Parameters

mixed $items

Return Value

Enumerable

in Collection at line 940
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

Exceptions

InvalidArgumentException

at line 668
Enumerable only(mixed $keys)

Return only the models from the collection with the specified keys.

Parameters

mixed $keys

Return Value

Enumerable

in Collection at line 986
Collection select(mixed $keys)

Select specific values from the items within the collection.

Parameters

mixed $keys

Return Value

Collection

in Collection at line 1006
mixed pop(int $count = 1)

Get and remove the last N items from the collection.

Parameters

int $count

Return Value

mixed

in Collection at line 1040
Collection prepend(mixed $value, mixed $key = null)

Push an item onto the beginning of the collection.

Parameters

mixed $value
mixed $key

Return Value

Collection

in Collection at line 1055
Collection push(mixed ...$values)

Push one or more items onto the end of the collection.

Parameters

mixed ...$values

Return Value

Collection

in Collection at line 1072
Collection unshift(mixed ...$values)

Prepend one or more items to the beginning of the collection.

Parameters

mixed ...$values

Return Value

Collection

in Collection at line 1087
Enumerable concat(iterable $source)

Push all of the given items onto the collection.

Parameters

iterable $source

Return Value

Enumerable

in Collection at line 1107
mixed pull(mixed $key, mixed $default = null)

Get and remove an item from the collection.

Parameters

mixed $key
mixed $default

Return Value

mixed

in Collection at line 1123
Collection put(mixed $key, mixed $value)

Put an item in the collection by key.

Parameters

mixed $key
mixed $value

Return Value

Collection

in Collection at line 1138
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

in Collection at line 1156
Enumerable replace(mixed $items)

Replace the collection items with the given items.

Parameters

mixed $items

Return Value

Enumerable

in Collection at line 1166
Enumerable replaceRecursive(mixed $items)

Recursively replace the collection items with the given items.

Parameters

mixed $items

Return Value

Enumerable

in Collection at line 1174
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

in Collection at line 1200
mixed before(mixed $value, bool $strict = false)

Get the item before the given item.

Parameters

mixed $value
bool $strict

Return Value

mixed

in Collection at line 1223
mixed after(mixed $value, bool $strict = false)

Get the item after the given item.

Parameters

mixed $value
bool $strict

Return Value

mixed

in Collection at line 1250
mixed shift(int $count = 1)

Get and remove the first N items from the collection.

Parameters

int $count

Return Value

mixed

Exceptions

InvalidArgumentException

in Collection at line 1284
Enumerable shuffle()

Shuffle the items in the collection.

Return Value

Enumerable

in Collection at line 1298
Collection|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

Collection|Enumerable

Exceptions

InvalidArgumentException

in Collection at line 1315
Enumerable skip(int $count)

Skip the first {$count} items.

Parameters

int $count

Return Value

Enumerable

in Collection at line 1325
Enumerable skipUntil(mixed $value)

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

Parameters

mixed $value

Return Value

Enumerable

in Collection at line 1335
Enumerable skipWhile(mixed $value)

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

Parameters

mixed $value

Return Value

Enumerable

in Collection at line 1343
Enumerable slice(int $offset, int|null $length = null)

Slice the underlying collection array.

Parameters

int $offset
int|null $length

Return Value

Enumerable

in Collection at line 1355
Enumerable split(int $numberOfGroups)

Split a collection into a certain number of groups.

Parameters

int $numberOfGroups

Return Value

Enumerable

Exceptions

InvalidArgumentException

in Collection at line 1398
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

Exceptions

InvalidArgumentException

in Collection at line 1416
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

in Collection at line 1442
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

in Collection at line 1462
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

in Collection at line 1484
Enumerable chunk(int $size, bool $preserveKeys = true)

Chunk the collection into chunks of the given size.

Parameters

int $size
bool $preserveKeys

Return Value

Enumerable

in Collection at line 1505
Enumerable chunkWhile(callable $callback)

Chunk the collection into chunks with a callback.

Parameters

callable $callback

Return Value

Enumerable

in Collection at line 1537
Enumerable sort(callable|int|null $callback = null)

Sort through each item with a callback.

Parameters

callable|int|null $callback

Return Value

Enumerable

in Collection at line 1553
Enumerable sortDesc(int $options = SORT_REGULAR)

Sort items in descending order.

Parameters

int $options

Return Value

Enumerable

in Collection at line 1568
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

in Collection at line 1606
protected Collection sortByMany(array $comparisons = [], int $options = SORT_REGULAR)

Sort the collection using multiple comparisons.

Parameters

array $comparisons
int $options

Return Value

Collection

in Collection at line 1669
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

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

Sort the collection keys.

Parameters

int $options
SortDirection|bool $descending

Return Value

Enumerable

in Collection at line 1706
Enumerable sortKeysDesc(int $options = SORT_REGULAR)

Sort the collection keys in descending order.

Parameters

int $options

Return Value

Enumerable

in Collection at line 1716
Enumerable sortKeysUsing(callable $callback)

Sort the collection keys using a callback.

Parameters

callable $callback

Return Value

Enumerable

in Collection at line 1732
Collection splice(int $offset, int|null $length = null, mixed $replacement = [])

Splice a portion of the underlying collection array.

Parameters

int $offset
int|null $length
mixed $replacement

Return Value

Collection

in Collection at line 1744
Enumerable take(int $limit)

Take the first or last {$limit} items.

Parameters

int $limit

Return Value

Enumerable

in Collection at line 1758
Enumerable takeUntil(mixed $value)

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

Parameters

mixed $value

Return Value

Enumerable

in Collection at line 1768
Enumerable takeWhile(mixed $value)

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

Parameters

mixed $value

Return Value

Enumerable

in Collection at line 1783
Collection transform(callable $callback)

Transform each item in the collection using a callback.

Parameters

callable $callback

Return Value

Collection

in Collection at line 1793
Enumerable dot(int|float $depth = INF)

Flatten a multi-dimensional associative array with dots.

Parameters

int|float $depth

Return Value

Enumerable

in Collection at line 1801
Enumerable undot()

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

Return Value

Enumerable

in Collection at line 1835
Enumerable values()

Reset the keys on the underlying array.

Return Value

Enumerable

at line 941
Collection|Enumerable zip(Arrayable|iterable ...$items)

Zip the collection together with one or more arrays.

Parameters

Arrayable|iterable ...$items

Return Value

Collection|Enumerable

at line 901
Collection|Enumerable pad(int $size, mixed $value)

Pad collection to the specified length with a value.

Parameters

int $size
mixed $value

Return Value

Collection|Enumerable

in Collection at line 1878
Traversable getIterator()

Get an iterator for the items.

Return Value

Traversable

in Collection at line 1888
int count()

Count the number of items in the collection.

Return Value

int

at line 844
Collection|Enumerable 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

Collection|Enumerable

in Collection at line 1912
Collection add(mixed $item)

Add an item to the collection.

Parameters

mixed $item

Return Value

Collection

in Collection at line 1924
Collection toBase()

Get a base Support collection instance from this collection.

Return Value

Collection

in Collection at line 1934
bool offsetExists(TKey $offset)

Determine if an item exists at an offset.

Parameters

TKey $offset

Return Value

bool

in Collection at line 1945
mixed offsetGet(TKey $offset)

Get an item at a given offset.

Parameters

TKey $offset

Return Value

mixed

in Collection at line 1956
void offsetSet(null|TKey $offset, TValue $value)

Set the item at a given offset.

Parameters

null|TKey $offset
TValue $value

Return Value

void

in Collection at line 1970
void offsetUnset(TKey $offset)

Unset the item at a given offset.

Parameters

TKey $offset

Return Value

void

in Collection at line 1978
static void flushState()

Flush all static state.

Return Value

void

protected int|string|null getDictionaryKey(mixed $attribute)

Get a dictionary key attribute - casting it to a string if necessary.

Parameters

mixed $attribute

Return Value

int|string|null

Exceptions

InvalidArgumentException

at line 37
mixed find(mixed $key, mixed $default = null)

Find a model in the collection by key.

Parameters

mixed $key
mixed $default

Return Value

mixed

at line 78
Model|Collection findOrFail(mixed $key)

Find a model in the collection by key or throw an exception.

Parameters

mixed $key

Return Value

Model|Collection

Exceptions

ModelNotFoundException

at line 117
Collection load(array|string $relations)

Load a set of relationships onto the collection.

Parameters

array|string $relations

Return Value

Collection

at line 143
Collection loadAggregate(array|string $relations, Expression|string $column, string|null $function = null)

Load a set of aggregations over relationship's column onto the collection.

Parameters

array|string $relations
Expression|string $column
string|null $function

Return Value

Collection

Exceptions

MissingAttributeException

at line 207
Collection loadCount(array|string $relations)

Load a set of relationship counts onto the collection.

Parameters

array|string $relations

Return Value

Collection

at line 221
Collection loadMax(array|string $relations, Expression|string $column)

Load a set of relationship's max column values onto the collection.

Parameters

array|string $relations
Expression|string $column

Return Value

Collection

at line 235
Collection loadMin(array|string $relations, Expression|string $column)

Load a set of relationship's min column values onto the collection.

Parameters

array|string $relations
Expression|string $column

Return Value

Collection

at line 249
Collection loadSum(array|string $relations, Expression|string $column)

Load a set of relationship's column summations onto the collection.

Parameters

array|string $relations
Expression|string $column

Return Value

Collection

at line 263
Collection loadAvg(array|string $relations, Expression|string $column)

Load a set of relationship's average column values onto the collection.

Parameters

array|string $relations
Expression|string $column

Return Value

Collection

at line 277
Collection loadExists(array|string $relations)

Load a set of related existences onto the collection.

Parameters

array|string $relations

Return Value

Collection

at line 291
Collection loadMissing(array|string $relations)

Load a set of relationships onto the collection if they are not already eager loaded.

Parameters

array|string $relations

Return Value

Collection

at line 329
void loadMissingRelationshipChain(array $tuples)

Load a relationship path for models of the given type if it is not already eager loaded.

Parameters

array $tuples

Return Value

void

at line 358
protected void loadMissingRelation(Collection $models, array $path)

Load a relationship path if it is not already eager loaded.

Parameters

Collection $models
array $path

Return Value

void

at line 397
Collection loadMorph(string $relation, array $relations)

Load a set of relationships onto the mixed relationship collection.

Parameters

string $relation
array $relations

Return Value

Collection

at line 418
Collection loadMorphCount(string $relation, array $relations)

Load a set of relationship counts onto the mixed relationship collection.

Parameters

string $relation
array $relations

Return Value

Collection

at line 474
array modelKeys()

Get the array of primary keys.

Return Value

array

at line 551
Collection fresh(array|string $with = [])

Reload a fresh model instance from the database for all the entities.

Parameters

array|string $with

Return Value

Collection

Exceptions

MissingAttributeException

at line 709
Collection makeHidden(array|string $attributes)

Make the given, typically visible, attributes hidden across the entire collection.

Parameters

array|string $attributes

Return Value

Collection

at line 721
Collection mergeHidden(array|string $attributes)

Merge the given, typically visible, attributes hidden across the entire collection.

Parameters

array|string $attributes

Return Value

Collection

at line 733
Collection setHidden(array $hidden)

Set the hidden attributes across the entire collection.

Parameters

array $hidden

Return Value

Collection

at line 745
Collection makeVisible(array|string $attributes)

Make the given, typically hidden, attributes visible across the entire collection.

Parameters

array|string $attributes

Return Value

Collection

at line 757
Collection mergeVisible(array|string $attributes)

Merge the given, typically hidden, attributes visible across the entire collection.

Parameters

array|string $attributes

Return Value

Collection

at line 769
Collection setVisible(array $visible)

Set the visible attributes across the entire collection.

Parameters

array $visible

Return Value

Collection

at line 781
Collection append(array|string $attributes)

Append an attribute across the entire collection.

Parameters

array|string $attributes

Return Value

Collection

at line 793
Collection setAppends(array $appends)

Sets the appends on every element of the collection, overwriting the existing appends for each.

Parameters

array $appends

Return Value

Collection

at line 804
Collection withoutAppends()

Remove appended properties from every element in the collection.

Return Value

Collection

at line 815
array getDictionary(iterable|null $items = null)

Get a dictionary keyed by primary keys.

Parameters

iterable|null $items

Return Value

array

at line 995
Collection withRelationshipAutoloading()

Enable relationship autoloading for all models in this collection.

Return Value

Collection

at line 1013
string|null getQueueableClass()

Get the type of the entities being queued.

Return Value

string|null

Exceptions

LogicException

at line 1033
protected string getQueueableModelClass(mixed $model)

Get the queueable class name for the given model.

Parameters

mixed $model

Return Value

string

at line 1048
array getQueueableIds()

Get the identifiers for all of the entities.

Return Value

array

Exceptions

LogicException
MissingAttributeException

at line 1073
array getQueueableRelations()

Get the relationships of the entities being queued.

Return Value

array

at line 1095
string|null getQueueableConnection()

Get the connection of the entities being queued.

Return Value

string|null

Exceptions

LogicException

at line 1120
Builder toQuery()

Get the Eloquent query builder from the collection.