trait EnumeratesValues (View source)

Properties

protected bool $escapeWhenCastingToString

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

static protected string[] $proxies

The methods that can be proxied.

HigherOrderCollectionProxy read-only $average
HigherOrderCollectionProxy read-only $avg
HigherOrderCollectionProxy read-only $contains
HigherOrderCollectionProxy read-only $doesntContain
HigherOrderCollectionProxy read-only $each
HigherOrderCollectionProxy read-only $every
HigherOrderCollectionProxy read-only $filter
HigherOrderCollectionProxy read-only $first
HigherOrderCollectionProxy read-only $flatMap
HigherOrderCollectionProxy read-only $groupBy
HigherOrderCollectionProxy read-only $keyBy
HigherOrderCollectionProxy read-only $map
HigherOrderCollectionProxy read-only $max
HigherOrderCollectionProxy read-only $min
HigherOrderCollectionProxy read-only $partition
HigherOrderCollectionProxy read-only $reject
HigherOrderCollectionProxy read-only $some
HigherOrderCollectionProxy read-only $sortBy
HigherOrderCollectionProxy read-only $sortByDesc
HigherOrderCollectionProxy read-only $skipUntil
HigherOrderCollectionProxy read-only $skipWhile
HigherOrderCollectionProxy read-only $sum
HigherOrderCollectionProxy read-only $takeUntil
HigherOrderCollectionProxy read-only $takeWhile
HigherOrderCollectionProxy read-only $unique
HigherOrderCollectionProxy read-only $until

Methods

make(mixed $items = [])

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

wrap(mixed $value)

Wrap the given value in a collection if applicable.

static array
unwrap(array|EnumeratesValues $value)

Get the underlying items from the given collection if applicable.

empty()

Create a new instance with no items.

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

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

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

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

Determine if an item exists, using strict comparison.

void
dd(mixed ...$args)

Dump the items and end the script.

$this
dump()

Dump the items.

$this
each(callable $callback)

Execute a callback over each item.

eachSpread(callable $callback)

Execute a callback over each nested chunk of items.

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

Determine if all items pass the given truth test.

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

Get the first item by the given key value pair.

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|string|null $callback = null)

Get the min value of a given key.

mixed
max(callable|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(callable|string $key, mixed $operator = null, mixed $value = null)

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

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

Get the sum of the given values.

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

Apply the callback if the value is truthy.

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

Apply the callback if the collection is empty.

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

Apply the callback if the collection is not empty.

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

Apply the callback if the value is falsy.

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

Apply the callback unless the collection is empty.

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

Apply the callback unless the collection is not empty.

where(string $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(string $key, mixed $value)

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

whereIn(string $key, mixed $values, bool $strict = false)

Filter items by the given key value pair.

whereInStrict(string $key, mixed $values)

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

whereBetween(string $key, array $values)

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

whereNotBetween(string $key, array $values)

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

whereNotIn(string $key, mixed $values, bool $strict = false)

Filter items by the given key value pair.

whereNotInStrict(string $key, mixed $values)

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

whereInstanceOf(string|string[] $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(callable[] $pipes)

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

$this
tap(callable $callback)

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

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

Reduce the collection to a single value.

array
reduceMany(callable $callback, mixed ...$initial) deprecated

Reduce the collection to multiple aggregate values.

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(callable|mixed $callback = true)

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

uniqueStrict(string|callable|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.

getCachingIterator(int $flags = CachingIterator::CALL_TOSTRING)

Get a CachingIterator instance.

string
__toString()

Convert the collection to its string representation.

$this
escapeWhenCastingToString(bool $escape = true)

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

static void
proxy(string $method)

Add a method to the list of proxied methods.

mixed
__get(string $key)

Dynamically access collection proxies.

array
getArrayableItems(mixed $items)

Results array of items from Collection or Arrayable.

operatorForWhere(string $key, string|null $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|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

static EnumeratesValues make(mixed $items = [])

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

Parameters

mixed $items

Return Value

EnumeratesValues

static EnumeratesValues wrap(mixed $value)

Wrap the given value in a collection if applicable.

Parameters

mixed $value

Return Value

EnumeratesValues

static array unwrap(array|EnumeratesValues $value)

Get the underlying items from the given collection if applicable.

Parameters

array|EnumeratesValues $value

Return Value

array

static EnumeratesValues empty()

Create a new instance with no items.

Return Value

EnumeratesValues

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

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

Parameters

int $number
callable|null $callback

Return Value

EnumeratesValues

mixed average(callable|string|null $callback = null)

Alias for the "avg" method.

Parameters

callable|string|null $callback

Return Value

mixed

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

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

Determine if an item exists, using strict comparison.

Parameters

mixed $key
mixed $value

Return Value

bool

void dd(mixed ...$args)

Dump the items and end the script.

Parameters

mixed ...$args

Return Value

void

$this dump()

Dump the items.

Return Value

$this

$this each(callable $callback)

Execute a callback over each item.

Parameters

callable $callback

Return Value

$this

EnumeratesValues eachSpread(callable $callback)

Execute a callback over each nested chunk of items.

Parameters

callable $callback

Return Value

EnumeratesValues

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

Determine if all items pass the given truth test.

Parameters

string|callable $key
mixed $operator
mixed $value

Return Value

bool

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

Get the first item by the given key value pair.

Parameters

string $key
mixed $operator
mixed $value

Return Value

mixed

bool isNotEmpty()

Determine if the collection is not empty.

Return Value

bool

EnumeratesValues mapSpread(callable $callback)

Run a map over each nested chunk of items.

Parameters

callable $callback

Return Value

EnumeratesValues

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

EnumeratesValues flatMap(callable $callback)

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

Parameters

callable $callback

Return Value

EnumeratesValues

EnumeratesValues mapInto(string $class)

Map the values into a new class.

Parameters

string $class

Return Value

EnumeratesValues

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

Get the min value of a given key.

Parameters

callable|string|null $callback

Return Value

mixed

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

Get the max value of a given key.

Parameters

callable|string|null $callback

Return Value

mixed

EnumeratesValues forPage(int $page, int $perPage)

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

Parameters

int $page
int $perPage

Return Value

EnumeratesValues

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

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

Parameters

callable|string $key
mixed $operator
mixed $value

Return Value

EnumeratesValues

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

Get the sum of the given values.

Parameters

callable|string|null $callback

Return Value

mixed

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

Apply the callback if the value is truthy.

Parameters

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

Return Value

EnumeratesValues|mixed

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

Apply the callback if the collection is empty.

Parameters

callable $callback
callable|null $default

Return Value

EnumeratesValues|mixed

EnumeratesValues|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

EnumeratesValues|mixed

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

Apply the callback if the value is falsy.

Parameters

bool $value
callable $callback
callable|null $default

Return Value

EnumeratesValues|mixed

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

Apply the callback unless the collection is empty.

Parameters

callable $callback
callable|null $default

Return Value

EnumeratesValues|mixed

EnumeratesValues|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

EnumeratesValues|mixed

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

Filter items by the given key value pair.

Parameters

string $key
mixed $operator
mixed $value

Return Value

EnumeratesValues

EnumeratesValues whereNull(string|null $key = null)

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

Parameters

string|null $key

Return Value

EnumeratesValues

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

EnumeratesValues whereStrict(string $key, mixed $value)

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

Parameters

string $key
mixed $value

Return Value

EnumeratesValues

EnumeratesValues whereIn(string $key, mixed $values, bool $strict = false)

Filter items by the given key value pair.

Parameters

string $key
mixed $values
bool $strict

Return Value

EnumeratesValues

EnumeratesValues whereInStrict(string $key, mixed $values)

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

Parameters

string $key
mixed $values

Return Value

EnumeratesValues

EnumeratesValues whereBetween(string $key, array $values)

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

Parameters

string $key
array $values

Return Value

EnumeratesValues

EnumeratesValues whereNotBetween(string $key, array $values)

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

Parameters

string $key
array $values

Return Value

EnumeratesValues

EnumeratesValues whereNotIn(string $key, mixed $values, bool $strict = false)

Filter items by the given key value pair.

Parameters

string $key
mixed $values
bool $strict

Return Value

EnumeratesValues

EnumeratesValues whereNotInStrict(string $key, mixed $values)

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

Parameters

string $key
mixed $values

Return Value

EnumeratesValues

EnumeratesValues whereInstanceOf(string|string[] $type)

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

Parameters

string|string[] $type

Return Value

EnumeratesValues

mixed pipe(callable $callback)

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

Parameters

callable $callback

Return Value

mixed

mixed pipeInto(string $class)

Pass the collection into a new class.

Parameters

string $class

Return Value

mixed

mixed pipeThrough(callable[] $pipes)

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

Parameters

callable[] $pipes

Return Value

mixed

$this tap(callable $callback)

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

Parameters

callable $callback

Return Value

$this

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

Reduce the collection to a single value.

Parameters

callable $callback
mixed $initial

Return Value

mixed

array reduceMany(callable $callback, mixed ...$initial) deprecated

deprecated Use "reduceSpread" instead

Reduce the collection to multiple aggregate values.

Parameters

callable $callback
mixed ...$initial

Return Value

array

Exceptions

UnexpectedValueException

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

Reduce the collection to multiple aggregate values.

Parameters

callable $callback
mixed ...$initial

Return Value

array

Exceptions

UnexpectedValueException

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

Reduce an associative collection to a single value.

Parameters

callable $callback
mixed $initial

Return Value

mixed

EnumeratesValues reject(callable|mixed $callback = true)

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

Parameters

callable|mixed $callback

Return Value

EnumeratesValues

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

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

Parameters

string|callable|null $key

Return Value

EnumeratesValues

Collection collect()

Collect the values into a collection.

Return Value

Collection

array toArray()

Get the collection of items as a plain array.

Return Value

array

array jsonSerialize()

Convert the object into something JSON serializable.

Return Value

array

string toJson(int $options = 0)

Get the collection of items as JSON.

Parameters

int $options

Return Value

string

CachingIterator getCachingIterator(int $flags = CachingIterator::CALL_TOSTRING)

Get a CachingIterator instance.

Parameters

int $flags

Return Value

CachingIterator

string __toString()

Convert the collection to its string representation.

Return Value

string

$this escapeWhenCastingToString(bool $escape = true)

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

Parameters

bool $escape

Return Value

$this

static void proxy(string $method)

Add a method to the list of proxied methods.

Parameters

string $method

Return Value

void

mixed __get(string $key)

Dynamically access collection proxies.

Parameters

string $key

Return Value

mixed

Exceptions

Exception

protected array getArrayableItems(mixed $items)

Results array of items from Collection or Arrayable.

Parameters

mixed $items

Return Value

array

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

Get an operator checker callback.

Parameters

string $key
string|null $operator
mixed $value

Return Value

Closure

protected bool useAsCallable(mixed $value)

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

Parameters

mixed $value

Return Value

bool

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

Get a value retrieving callback.

Parameters

callable|string|null $value

Return Value

callable

protected Closure equality(mixed $value)

Make a function to check an item's equality.

Parameters

mixed $value

Return Value

Closure

protected Closure negate(Closure $callback)

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

Parameters

Closure $callback

Return Value

Closure

protected Closure identity()

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

Return Value

Closure

Laravel Cloud is the best place to deploy Laravel, Nuxt, Express, Hono, Node.js, Bun, Go, Flask, Python, and more, with dedicated infrastructure available on AWS through Laravel Private Cloud.