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, static> read-only | $average | ||
| TValue, static> read-only | $avg | ||
| TValue, static> read-only | $contains | ||
| TValue, static> read-only | $doesntContain | ||
| TValue, static> read-only | $each | ||
| TValue, static> read-only | $every | ||
| TValue, static> read-only | $filter | ||
| TValue, static> read-only | $first | ||
| TValue, static> read-only | $flatMap | ||
| TValue, static> read-only | $groupBy | ||
| TValue, static> read-only | $hasMany | ||
| TValue, static> read-only | $hasSole | ||
| TValue, static> read-only | $keyBy | ||
| TValue, static> read-only | $last | ||
| TValue, static> read-only | $map | ||
| TValue, static> read-only | $max | ||
| TValue, static> read-only | $min | ||
| TValue, static> read-only | $partition | ||
| TValue, static> read-only | $percentage | ||
| TValue, static> read-only | $reject | ||
| TValue, static> read-only | $skipUntil | ||
| TValue, static> read-only | $skipWhile | ||
| TValue, static> read-only | $sole | ||
| TValue, static> read-only | $some | ||
| TValue, static> read-only | $sortBy | ||
| TValue, static> read-only | $sortByDesc | ||
| TValue, static> read-only | $sum | ||
| TValue, static> read-only | $takeUntil | ||
| TValue, static> read-only | $takeWhile | ||
| TValue, static> read-only | $unique | ||
| TValue, static> read-only | $unless | ||
| TValue, static> read-only | $until | ||
| TValue, static> 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.
Chunk the collection into chunks by comparing adjacent values using the given key or callback.
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 129
static EnumeratesValues
make(mixed $items = [], mixed ...$args)
Create a new collection instance if the value isn't one already.
at line 142
static EnumeratesValues
wrap(mixed $value, mixed ...$args)
Wrap the given value in a collection if applicable.
at line 159
static mixed
unwrap(mixed $value)
Get the underlying items from the given collection if applicable.
at line 167
static EnumeratesValues
empty(mixed ...$args)
Create a new instance with no items.
at line 180
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.
at line 196
static EnumeratesValues
fromJson(string $json, int $depth = 513, int $flags = 0, mixed ...$args)
Create a new collection by decoding a JSON string.
at line 207
float|int|null
avg(callable|int|string|null $callback = null)
Get the average value of a given key.
at line 228
float|int|null
average(callable|string|null $callback = null)
Alias for the "avg" method.
at line 238
bool
some(mixed $key, mixed $operator = null, mixed $value = null)
Alias for the "contains" method.
at line 246
never
dd(mixed ...$args)
Dump the given arguments and terminate execution.
at line 254
EnumeratesValues
dump(mixed ...$args)
Dump the items.
at line 266
EnumeratesValues
each(callable $callback)
Execute a callback over each item.
at line 280
EnumeratesValues
eachSpread(callable $callback)
Execute a callback over each nested chunk of items.
at line 292
bool
every(mixed $key, mixed $operator = null, mixed $value = null)
Determine if all items pass the given truth test.
at line 314
mixed
firstWhere(callable|string $key, mixed $operator = null, mixed $value = null)
Get the first item by the given key value pair.
at line 324
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 345
mixed
value(string $key, mixed $default = null)
Get a single key's value from the first matching item in the collection.
at line 364
EnumeratesValues
ensure(string|array $type)
Ensure that every item in the collection is of the expected type.
at line 393
bool
isNotEmpty()
Determine if the collection is not empty.
at line 403
Collection|EnumeratesValues
mapSpread(callable $callback)
Run a map over each nested chunk of items.
at line 421
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.
at line 437
Collection|EnumeratesValues
flatMap(callable $callback)
Map a collection and flatten the result by a single level.
at line 450
Collection|EnumeratesValues
mapInto(string $class)
Map the values into a new class.
at line 467
mixed
min(callable|int|string|null $callback = null)
Get the min value of a given key.
at line 484
mixed
max(callable|int|string|null $callback = null)
Get the max value of a given key.
at line 498
EnumeratesValues
forPage(int $page, int $perPage)
"Paginate" the collection by slicing it into a smaller collection.
at line 511
Collection|EnumeratesValues
partition(mixed $key, mixed $operator = null, mixed $value = null)
Partition the collection into two arrays using the given callback or key.
at line 528
float|null
percentage(callable $callback, int $precision = 2)
Calculate the percentage of items that pass a given truth test.
at line 548
mixed
sum(callable|int|string|null $callback = null)
Get the sum of the given values.
at line 566
mixed
whenEmpty(callable $callback, callable|null $default = null)
Apply the callback if the collection is empty.
at line 580
mixed
whenNotEmpty(callable $callback, callable|null $default = null)
Apply the callback if the collection is not empty.
at line 594
mixed
unlessEmpty(callable $callback, callable|null $default = null)
Apply the callback unless the collection is empty.
at line 608
mixed
unlessNotEmpty(callable $callback, callable|null $default = null)
Apply the callback unless the collection is not empty.
at line 616
EnumeratesValues
where(callable|string|null $key, mixed $operator = null, mixed $value = null)
Filter items by the given key value pair.
at line 624
EnumeratesValues
whereNull(string|null $key = null)
Filter items where the value for the given key is null.
at line 632
EnumeratesValues
whereNotNull(string|null $key = null)
Filter items where the value for the given key is not null.
at line 640
EnumeratesValues
whereStrict(callable|string|null $key, mixed $value)
Filter items by the given key value pair using strict comparison.
at line 648
EnumeratesValues
whereIn(string $key, Arrayable|iterable $values, bool $strict = false)
Filter items by the given key value pair.
at line 658
EnumeratesValues
whereInStrict(string $key, Arrayable|iterable $values)
Filter items by the given key value pair using strict comparison.
at line 666
EnumeratesValues
whereBetween(string $key, Arrayable|iterable $values)
Filter items such that the value of the given key is between the given values.
at line 676
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 692
EnumeratesValues
whereNotIn(string $key, Arrayable|iterable $values, bool $strict = false)
Filter items by the given key value pair.
at line 702
EnumeratesValues
whereNotInStrict(string $key, Arrayable|iterable $values)
Filter items by the given key value pair using strict comparison.
at line 715
EnumeratesValues
whereInstanceOf(string|array $type)
Filter the items, removing any items that don't match the given type(s).
at line 742
mixed
pipe(callable $callback)
Pass the collection to the given callback and return the result.
at line 755
mixed
pipeInto(string $class)
Pass the collection into a new class.
at line 765
mixed
pipeThrough(array $callbacks)
Pass the collection through a series of callable pipes and return the result.
at line 783
mixed
reduce(callable $callback, mixed $initial = null)
Reduce the collection to a single value.
at line 803
mixed
reduceInto(mixed $initial, callable $callback)
Reduce the collection to a single value by mutating an initial value.
at line 817
array
reduceSpread(callable $callback, mixed ...$initial)
Reduce the collection to multiple aggregate values.
at line 846
mixed
reduceWithKeys(callable $callback, mixed $initial = null)
Reduce an associative collection to a single value.
at line 856
EnumeratesValues
reject(mixed $callback = true)
Create a collection of all elements that do not pass a given truth test.
at line 873
EnumeratesValues
chunkBy(callable|string $key)
Chunk the collection into chunks by comparing adjacent values using the given key or callback.
at line 888
EnumeratesValues
tap(callable $callback)
Pass the collection to the given callback and then return it.
at line 900
EnumeratesValues
unique(callable|int|string|null $key = null, bool $strict = false)
Return only unique items from the collection array.
at line 920
EnumeratesValues
uniqueStrict(callable|string|null $key = null)
Return only unique items from the collection array using strict comparison.
at line 930
Collection
collect()
Collect the values into a collection.
at line 940
array
toArray()
Get the collection of items as a plain array.
at line 950
array
jsonSerialize()
Convert the object into something JSON serializable.
at line 968
string
toJson(int $options = 0)
Get the collection of items as JSON.
at line 978
string
toPrettyJson(int $options = 0)
Get the collection of items as pretty print formatted JSON.
at line 986
CachingIterator
getCachingIterator(int $flags = CachingIterator::CALL_TOSTRING)
Get a CachingIterator instance.
at line 995
string
__toString()
Convert the collection to its string representation.
at line 1005
EnumeratesValues
escapeWhenCastingToString(bool $escape = true)
Indicate that the model's string representation should be escaped when __toString is invoked.
at line 1019
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 1030
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 1040
mixed
__get(string $key)
Dynamically access collection proxies.
at line 1054
protected array
getArrayableItems(mixed $items)
Results array of items from Collection or Arrayable.
at line 1064
protected callable
operatorForWhere(callable|string|null $key, mixed $operator = null, mixed $value = null)
Get an operator checker callback.
at line 1118
protected bool
useAsCallable(mixed $value)
Determine if the given value is callable, but not a string.
at line 1126
protected callable
valueRetriever(callable|int|string|null $value)
Get a value retrieving callback.
at line 1140
protected Closure
equality(mixed $value)
Make a function to check an item's equality.
at line 1148
protected Closure
negate(Closure $callback)
Make a function using another function, by negating its result.
at line 1158
protected Closure
identity()
Make a function that returns what's passed to it.