EnumeratesValues
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
Apply the callback if the given "value" is (or resolves to) truthy.
Apply the callback if the given "value" is (or resolves to) falsy.
Create a new collection instance if the value isn't one already.
Wrap the given value in a collection if applicable.
Get the underlying items from the given collection if applicable.
Create a new instance with no items.
Create a new collection by invoking the callback a given amount of times.
Create a new collection by decoding a JSON string.
Get the average value of a given key.
Alias for the "avg" method.
Alias for the "contains" method.
Dump the given arguments and terminate execution.
Dump the items.
Execute a callback over each item.
Execute a callback over each nested chunk of items.
Determine if all items pass the given truth test.
Get the first item by the given key value pair.
Determine if the collection contains multiple items, optionally matching the given criteria.
Get a single key's value from the first matching item in the collection.
Ensure that every item in the collection is of the expected type.
Determine if the collection is not empty.
Run a map over each nested chunk of items.
Run a grouping map over the items.
Map a collection and flatten the result by a single level.
Map the values into a new class.
Get the min value of a given key.
Get the max value of a given key.
"Paginate" the collection by slicing it into a smaller collection.
Partition the collection into two arrays using the given callback or key.
Calculate the percentage of items that pass a given truth test.
Get the sum of the given values.
Apply the callback if the collection is empty.
Apply the callback if the collection is not empty.
Apply the callback unless the collection is empty.
Apply the callback unless the collection is not empty.
Filter items by the given key value pair.
Filter items where the value for the given key is null.
Filter items where the value for the given key is not null.
Filter items by the given key value pair using strict comparison.
Filter items by the given key value pair using strict comparison.
Filter items such that the value of the given key is between the given values.
Filter items such that the value of the given key is not between the given values.
Filter items by the given key value pair.
Filter items by the given key value pair using strict comparison.
Filter the items, removing any items that don't match the given type(s).
Pass the collection to the given callback and return the result.
Pass the collection into a new class.
Pass the collection through a series of callable pipes and return the result.
Reduce the collection to a single value.
Reduce the collection to a single value by mutating an initial value.
Reduce the collection to multiple aggregate values.
Reduce an associative collection to a single value.
Create a collection of all elements that do not pass a given truth test.
Pass the collection to the given callback and then return it.
Return only unique items from the collection array.
Return only unique items from the collection array using strict comparison.
Collect the values into a collection.
Get the collection of items as a plain array.
Convert the object into something JSON serializable.
Get the collection of items as JSON.
Get the collection of items as pretty print formatted JSON.
Get a CachingIterator instance.
Convert the collection to its string representation.
Indicate that the model's string representation should be escaped when __toString is invoked.
Add a method to the list of proxied methods.
Flush the registered proxies, restoring the default list.
Dynamically access collection proxies.
Results array of items from Collection or Arrayable.
Get an operator checker callback.
Determine if the given value is callable, but not a string.
Get a value retrieving callback.
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.
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.
at line 125
static EnumeratesValues
make(mixed $items = [], mixed ...$args)
Create a new collection instance if the value isn't one already.
at line 138
static EnumeratesValues
wrap(mixed $value, mixed ...$args)
Wrap the given value in a collection if applicable.
at line 154
static mixed
unwrap(mixed $value)
Get the underlying items from the given collection if applicable.
at line 162
static EnumeratesValues
empty(mixed ...$args)
Create a new instance with no items.
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.
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.
at line 201
float|int|null
avg(callable|int|string|null $callback = null)
Get the average value of a given key.
at line 222
float|int|null
average(callable|string|null $callback = null)
Alias for the "avg" method.
at line 232
bool
some(mixed $key, mixed $operator = null, mixed $value = null)
Alias for the "contains" method.
at line 240
never
dd(mixed ...$args)
Dump the given arguments and terminate execution.
at line 248
EnumeratesValues
dump(mixed ...$args)
Dump the items.
at line 260
EnumeratesValues
each(callable $callback)
Execute a callback over each item.
at line 276
EnumeratesValues
eachSpread(callable $callback)
Execute a callback over each nested chunk of items.
at line 290
bool
every(mixed $key, mixed $operator = null, mixed $value = null)
Determine if all items pass the given truth test.
at line 312
mixed
firstWhere(callable|string $key, mixed $operator = null, mixed $value = null)
Get the first item by the given key value pair.
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.
at line 343
mixed
value(string $key, mixed $default = null)
Get a single key's value from the first matching item in the collection.
at line 362
EnumeratesValues
ensure(string|array $type)
Ensure that every item in the collection is of the expected type.
at line 391
bool
isNotEmpty()
Determine if the collection is not empty.
at line 404
EnumeratesValues
mapSpread(callable $callback)
Run a map over each nested chunk of items.
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.
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.
at line 456
TMapIntoValue>
mapInto(string $class)
Map the values into a new class.
at line 473
mixed
min(callable|int|string|null $callback = null)
Get the min value of a given key.
at line 490
mixed
max(callable|int|string|null $callback = null)
Get the max value of a given key.
at line 504
EnumeratesValues
forPage(int $page, int $perPage)
"Paginate" the collection by slicing it into a smaller collection.
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.
at line 534
float|null
percentage(callable $callback, int $precision = 2)
Calculate the percentage of items that pass a given truth test.
at line 554
mixed
sum(callable|int|string|null $callback = null)
Get the sum of the given values.
at line 572
mixed
whenEmpty(callable $callback, callable|null $default = null)
Apply the callback if the collection is empty.
at line 586
mixed
whenNotEmpty(callable $callback, callable|null $default = null)
Apply the callback if the collection is not empty.
at line 600
mixed
unlessEmpty(callable $callback, callable|null $default = null)
Apply the callback unless the collection is empty.
at line 614
mixed
unlessNotEmpty(callable $callback, callable|null $default = null)
Apply the callback unless the collection is not empty.
at line 622
EnumeratesValues
where(callable|string|null $key, mixed $operator = null, mixed $value = null)
Filter items by the given key value pair.
at line 630
EnumeratesValues
whereNull(string|null $key = null)
Filter items where the value for the given key is null.
at line 638
EnumeratesValues
whereNotNull(string|null $key = null)
Filter items where the value for the given key is not null.
at line 646
EnumeratesValues
whereStrict(callable|string|null $key, mixed $value)
Filter items by the given key value pair using strict comparison.
at line 654
EnumeratesValues
whereIn(string $key, Arrayable|iterable $values, bool $strict = false)
Filter items by the given key value pair.
at line 664
EnumeratesValues
whereInStrict(string $key, Arrayable|iterable $values)
Filter items by the given key value pair using strict comparison.
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.
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.
at line 690
EnumeratesValues
whereNotIn(string $key, Arrayable|iterable $values, bool $strict = false)
Filter items by the given key value pair.
at line 700
EnumeratesValues
whereNotInStrict(string $key, Arrayable|iterable $values)
Filter items by the given key value pair using strict comparison.
at line 713
EnumeratesValues
whereInstanceOf(string|array $type)
Filter the items, removing any items that don't match the given type(s).
at line 739
mixed
pipe(callable $callback)
Pass the collection to the given callback and return the result.
at line 752
mixed
pipeInto(string $class)
Pass the collection into a new class.
at line 762
mixed
pipeThrough(array $callbacks)
Pass the collection through a series of callable pipes and return the result.
at line 780
mixed
reduce(callable $callback, mixed $initial = null)
Reduce the collection to a single value.
at line 800
mixed
reduceInto(mixed $initial, callable $callback)
Reduce the collection to a single value by mutating an initial value.
at line 814
array
reduceSpread(callable $callback, mixed ...$initial)
Reduce the collection to multiple aggregate values.
at line 843
mixed
reduceWithKeys(callable $callback, mixed $initial = null)
Reduce an associative collection to a single value.
at line 853
EnumeratesValues
reject(mixed $callback = true)
Create a collection of all elements that do not pass a given truth test.
at line 869
EnumeratesValues
tap(callable $callback)
Pass the collection to the given callback and then return it.
at line 881
EnumeratesValues
unique(callable|int|string|null $key = null, bool $strict = false)
Return only unique items from the collection array.
at line 901
EnumeratesValues
uniqueStrict(callable|string|null $key = null)
Return only unique items from the collection array using strict comparison.
at line 911
Collection
collect()
Collect the values into a collection.
at line 921
array
toArray()
Get the collection of items as a plain array.
at line 931
array
jsonSerialize()
Convert the object into something JSON serializable.
at line 946
string
toJson(int $options = 0)
Get the collection of items as JSON.
at line 954
string
toPrettyJson(int $options = 0)
Get the collection of items as pretty print formatted JSON.
at line 962
CachingIterator
getCachingIterator(int $flags = CachingIterator::CALL_TOSTRING)
Get a CachingIterator instance.
at line 971
string
__toString()
Convert the collection to its string representation.
at line 981
EnumeratesValues
escapeWhenCastingToString(bool $escape = true)
Indicate that the model's string representation should be escaped when __toString is invoked.
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.
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.
at line 1016
mixed
__get(string $key)
Dynamically access collection proxies.
at line 1030
protected array
getArrayableItems(mixed $items)
Results array of items from Collection or Arrayable.
at line 1040
protected callable
operatorForWhere(callable|string|null $key, mixed $operator = null, mixed $value = null)
Get an operator checker callback.
at line 1094
protected bool
useAsCallable(mixed $value)
Determine if the given value is callable, but not a string.
at line 1102
protected callable
valueRetriever(callable|int|string|null $value)
Get a value retrieving callback.
at line 1116
protected Closure
equality(mixed $value)
Make a function to check an item's equality.
at line 1124
protected Closure
negate(Closure $callback)
Make a function using another function, by negating its result.
at line 1134
protected Closure
identity()
Make a function that returns what's passed to it.