trait EnumeratesValues

Traits

Constants

protected DEFAULT_PROXIES

The default methods that can be proxied.

Properties

protected bool $escapeWhenCastingToString

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

static protected array<int, string> $proxies

The methods that can be proxied.

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

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 = 512, 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.

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.

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.

TValue>>
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.

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 array.

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.

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

at line 125
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

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

Wrap the given value in a collection if applicable.

Parameters

mixed $value
mixed ...$args

Return Value

EnumeratesValues

at line 154
static mixed unwrap(mixed $value)

Get the underlying items from the given collection if applicable.

Parameters

mixed $value

Return Value

mixed

at line 162
static EnumeratesValues empty(mixed ...$args)

Create a new instance with no items.

Parameters

mixed ...$args

Return Value

EnumeratesValues

at line 175
static 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

EnumeratesValues

at line 191
static EnumeratesValues fromJson(string $json, int $depth = 512, 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

at line 201
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 222
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 232
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 240
never dd(mixed ...$args)

Dump the given arguments and terminate execution.

Parameters

mixed ...$args

Return Value

never

at line 248
EnumeratesValues dump(mixed ...$args)

Dump the items.

Parameters

mixed ...$args

Return Value

EnumeratesValues

at line 260
EnumeratesValues each(callable $callback)

Execute a callback over each item.

Parameters

callable $callback

Return Value

EnumeratesValues

at line 276
EnumeratesValues eachSpread(callable $callback)

Execute a callback over each nested chunk of items.

Parameters

callable $callback

Return Value

EnumeratesValues

at line 290
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 312
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 322
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 343
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

at line 362
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

at line 391
bool isNotEmpty()

Determine if the collection is not empty.

Return Value

bool

at line 404
EnumeratesValues mapSpread(callable $callback)

Run a map over each nested chunk of items.

Parameters

callable $callback

Return Value

EnumeratesValues

at line 424
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

EnumeratesValues

at line 443
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 456
TMapIntoValue> mapInto(string $class)

Map the values into a new class.

Parameters

string $class

Return Value

TMapIntoValue>

at line 473
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 490
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 504
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 517
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 534
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

at line 554
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 572
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 586
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 600
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 614
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 622
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

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

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

Parameters

string|null $key

Return Value

EnumeratesValues

at line 638
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

at line 646
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

at line 654
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

at line 664
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

at line 672
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

at line 680
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

at line 690
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

at line 700
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

at line 713
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

at line 739
mixed pipe(callable $callback)

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

Parameters

callable $callback

Return Value

mixed

at line 752
mixed pipeInto(string $class)

Pass the collection into a new class.

Parameters

string $class

Return Value

mixed

at line 762
mixed pipeThrough(array $callbacks)

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

Parameters

array $callbacks

Return Value

mixed

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

Reduce the collection to a single value.

Parameters

callable $callback
mixed $initial

Return Value

mixed

at line 800
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 814
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 843
mixed reduceWithKeys(callable $callback, mixed $initial = null)

Reduce an associative collection to a single value.

Parameters

callable $callback
mixed $initial

Return Value

mixed

at line 853
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

at line 869
EnumeratesValues tap(callable $callback)

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

Parameters

callable $callback

Return Value

EnumeratesValues

at line 881
EnumeratesValues 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

EnumeratesValues

at line 901
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

at line 911
Collection collect()

Collect the values into a collection.

Return Value

Collection

at line 921
array toArray()

Get the collection of items as a plain array.

Return Value

array

at line 931
array jsonSerialize()

Convert the object into something JSON serializable.

Return Value

array

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

Get the collection of items as JSON.

Parameters

int $options

Return Value

string

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

Get the collection of items as pretty print formatted JSON.

Parameters

int $options

Return Value

string

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

Get a CachingIterator instance.

Parameters

int $flags

Return Value

CachingIterator

at line 971
string __toString()

Convert the collection to its string representation.

Return Value

string

at line 981
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

at line 995
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 1006
static void flushProxies()

Flush the registered proxies, restoring the default list.

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

Return Value

void

at line 1016
mixed __get(string $key)

Dynamically access collection proxies.

Parameters

string $key

Return Value

mixed

Exceptions

Exception

at line 1030
protected array getArrayableItems(mixed $items)

Results array of items from Collection or Arrayable.

Parameters

mixed $items

Return Value

array

at line 1040
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

at line 1094
protected bool useAsCallable(mixed $value)

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

Parameters

mixed $value

Return Value

bool

at line 1102
protected callable valueRetriever(callable|int|string|null $value)

Get a value retrieving callback.

Parameters

callable|int|string|null $value

Return Value

callable

at line 1116
protected Closure equality(mixed $value)

Make a function to check an item's equality.

Parameters

mixed $value

Return Value

Closure

at line 1124
protected Closure negate(Closure $callback)

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

Parameters

Closure $callback

Return Value

Closure

at line 1134
protected Closure identity()

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

Return Value

Closure