LazyCollection
class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable, Transient
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 |
| TValue>|TValue>|LazyCollection | $source | The source from which to generate items. |
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.
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.
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.
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.
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 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.
Get the collection of items as pretty print formatted JSON.
Get a CachingIterator instance.
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.
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.
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Create a new lazy collection instance.
Create a new instance of the collection.
Create a collection with the given range.
Get all items in the enumerable.
Eager load all items into a new lazy collection backed by an array.
Cache values as they're enumerated.
Get the median of a given key.
Get the mode of a given key.
Collapse the collection of items into a single array.
Collapse the collection of items into a single array while preserving its keys.
Determine if an item exists in the enumerable.
Determine if an item exists, using strict comparison.
Determine if an item is not contained in the enumerable.
Determine if an item is not contained in the enumerable, using strict comparison.
Count the number of items in the collection by a field or using a callback.
Get the items that are not present in the given items.
Get the items that are not present in the given items, using the callback.
Get the items whose keys and values are not present in the given items, using the callback.
Get the items whose keys are not present in the given items, using the callback.
Retrieve duplicate items from the collection.
Retrieve duplicate items from the collection using strict comparison.
Get all items except for those with the specified keys.
Run a filter over each of the items.
Get the first item from the enumerable passing the given truth test.
Get a flattened list of the items in the collection.
Flip the items in the collection.
Get an item by key.
Group an associative array by a field or using a callback.
Key an associative array by a field or using a callback.
Determine if an item exists in the collection by key.
Determine if any of the keys exist in the collection.
Concatenate values of a given key as a string.
Intersect the collection with the given items.
Intersect the collection with the given items, using the callback.
Intersect the collection with the given items with additional index check.
Intersect the collection with the given items with additional index check, using the callback.
Intersect the collection with the given items by key.
Determine if the items are empty or not.
Join all items from the collection using a string. The final items can use a separate glue string.
Get the keys of the collection items.
Get the last item from the collection.
Run a map over each of the items.
Run a dictionary map over the items.
Run an associative map over each of the items.
Merge the collection with the given items.
Recursively merge the collection with the given items.
Multiply the items in the collection by the multiplier.
Union the collection with the given items.
Create a new collection consisting of every n-th element.
Get the items with the specified keys.
Select specific values from the items within the collection.
Push all of the given items onto the collection.
Get one or a specified number of items randomly from the collection.
Replace the collection items with the given items.
Recursively replace the collection items with the given items.
Reverse items order.
Search the collection for a given value and return the corresponding key if successful.
Get the item before the given item.
Get the item after the given item.
Shuffle the items in the collection.
Create chunks representing a "sliding window" view of the items in the collection.
Skip the first {$count} items.
Skip items in the collection until the given condition is met.
Skip items in the collection while the given condition is met.
Get a slice of items from the enumerable.
Split a collection into a certain number of groups.
Get the first item in the collection, but only if exactly one item exists. Otherwise, throw an exception.
Determine if the collection contains a single item or a single item matching the given criteria.
Get the first item in the collection but throw an exception if no matching items exist.
Chunk the collection into chunks of the given size.
Split a collection into a certain number of groups, and fill the first groups completely.
Chunk the collection into chunks with a callback.
Sort through each item with a callback.
Sort items in descending order.
Sort the collection using the given callback.
Sort the collection in descending order using the given callback.
Sort the collection keys.
Sort the collection keys in descending order.
Sort the collection keys using a callback.
Take the first or last {$limit} items.
Take items in the collection until the given condition is met.
Take items in the collection until a given point in time, with an optional callback on timeout.
Take items in the collection while the given condition is met.
Pass each item in the collection to the given callback, lazily.
Throttle the values, releasing them at most once per the given seconds.
Flatten a multi-dimensional associative array with dots.
Convert a flatten "dot" notation array into an expanded array.
Reset the keys on the underlying array.
Run the given callback every time the interval has passed.
Pad collection to the specified length with a value.
Get the values iterator.
Count the number of items in the collection.
Make an iterator from the given source.
Explode the "value" and "key" arguments passed to "pluck".
Pass this lazy collection through a method on the collection class.
Get the current time.
Get the precise current time.
Sleep for the given amount of microseconds.
Flush all static state.
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 99
static Enumerable
make(Arrayable|iterable|null $items = [], mixed ...$args)
Create a new collection instance if the value isn't one already.
in
EnumeratesValues at line 141
static EnumeratesValues
wrap(mixed $value, mixed ...$args)
Wrap the given value in a collection if applicable.
in
EnumeratesValues at line 158
static mixed
unwrap(mixed $value)
Get the underlying items from the given collection if applicable.
in
EnumeratesValues at line 166
static EnumeratesValues
empty(mixed ...$args)
Create a new instance with no items.
at line 138
static Collection|Enumerable
times(int $number, callable|null $callback = null, mixed ...$args)
Create a new collection by invoking the callback a given amount of times.
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.
in
EnumeratesValues at line 206
float|int|null
avg(callable|int|string|null $callback = null)
Get the average value of a given key.
in
EnumeratesValues at line 227
float|int|null
average(callable|string|null $callback = null)
Alias for the "avg" method.
in
EnumeratesValues at line 237
bool
some(mixed $key, mixed $operator = null, mixed $value = null)
Alias for the "contains" method.
in
EnumeratesValues at line 245
never
dd(mixed ...$args)
Dump the given arguments and terminate execution.
in
EnumeratesValues at line 255
EnumeratesValues
dump(mixed ...$args)
Dump the items.
in
EnumeratesValues at line 268
EnumeratesValues
each(callable $callback)
Execute a callback over each item.
in
EnumeratesValues at line 282
EnumeratesValues
eachSpread(callable $callback)
Execute a callback over each nested chunk of items.
in
EnumeratesValues at line 294
bool
every(mixed $key, mixed $operator = null, mixed $value = null)
Determine if all items pass the given truth test.
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.
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.
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.
in
EnumeratesValues at line 366
EnumeratesValues
ensure(string|array $type)
Ensure that every item in the collection is of the expected type.
in
EnumeratesValues at line 395
bool
isNotEmpty()
Determine if the collection is not empty.
at line 813
Collection|Enumerable
mapSpread(callable $callback)
Run a map over each nested chunk of items.
at line 850
Collection|Enumerable
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 886
Collection|Enumerable
flatMap(callable $callback)
Map a collection and flatten the result by a single level.
at line 899
Collection|Enumerable
mapInto(string $class)
Map the values into a new class.
in
EnumeratesValues at line 469
mixed
min(callable|int|string|null $callback = null)
Get the min value of a given key.
in
EnumeratesValues at line 486
mixed
max(callable|int|string|null $callback = null)
Get the max value of a given key.
in
EnumeratesValues at line 500
EnumeratesValues
forPage(int $page, int $perPage)
"Paginate" the collection by slicing it into a smaller collection.
at line 1096
Collection|Enumerable
partition(mixed $key, mixed $operator = null, mixed $value = null)
Partition the collection into two arrays using the given callback or key.
in
EnumeratesValues at line 530
float|null
percentage(callable $callback, int $precision = 2)
Calculate the percentage of items that pass a given truth test.
in
EnumeratesValues at line 550
mixed
sum(callable|int|string|null $callback = null)
Get the sum of the given values.
in
EnumeratesValues at line 568
mixed
whenEmpty(callable $callback, callable|null $default = null)
Apply the callback if the collection is empty.
in
EnumeratesValues at line 582
mixed
whenNotEmpty(callable $callback, callable|null $default = null)
Apply the callback if the collection is not empty.
in
EnumeratesValues at line 596
mixed
unlessEmpty(callable $callback, callable|null $default = null)
Apply the callback unless the collection is empty.
in
EnumeratesValues at line 610
mixed
unlessNotEmpty(callable $callback, callable|null $default = null)
Apply the callback unless the collection is not empty.
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.
in
EnumeratesValues at line 626
EnumeratesValues
whereNull(string|null $key = null)
Filter items where the value for the given key is null.
in
EnumeratesValues at line 634
EnumeratesValues
whereNotNull(string|null $key = null)
Filter items where the value for the given key is not null.
in
EnumeratesValues at line 642
EnumeratesValues
whereStrict(callable|string|null $key, mixed $value)
Filter items by the given key value pair using strict comparison.
in
EnumeratesValues at line 650
EnumeratesValues
whereIn(string $key, Arrayable|iterable $values, bool $strict = false)
Filter items by the given key value pair.
in
EnumeratesValues at line 660
EnumeratesValues
whereInStrict(string $key, Arrayable|iterable $values)
Filter items by the given key value pair using strict comparison.
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.
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.
in
EnumeratesValues at line 694
EnumeratesValues
whereNotIn(string $key, Arrayable|iterable $values, bool $strict = false)
Filter items by the given key value pair.
in
EnumeratesValues at line 704
EnumeratesValues
whereNotInStrict(string $key, Arrayable|iterable $values)
Filter items by the given key value pair using strict comparison.
in
EnumeratesValues at line 717
EnumeratesValues
whereInstanceOf(string|array $type)
Filter the items, removing any items that don't match the given type(s).
in
EnumeratesValues at line 744
mixed
pipe(callable $callback)
Pass the collection to the given callback and return the result.
in
EnumeratesValues at line 757
mixed
pipeInto(string $class)
Pass the collection into a new class.
in
EnumeratesValues at line 767
mixed
pipeThrough(array $callbacks)
Pass the collection through a series of callable pipes and return the result.
in
EnumeratesValues at line 785
mixed
reduce(callable $callback, mixed $initial = null)
Reduce the collection to a single value.
in
EnumeratesValues at line 805
mixed
reduceInto(mixed $initial, callable $callback)
Reduce the collection to a single value by mutating an initial value.
in
EnumeratesValues at line 819
array
reduceSpread(callable $callback, mixed ...$initial)
Reduce the collection to multiple aggregate values.
in
EnumeratesValues at line 848
mixed
reduceWithKeys(callable $callback, mixed $initial = null)
Reduce an associative collection to a single value.
in
EnumeratesValues at line 858
EnumeratesValues
reject(mixed $callback = true)
Create a collection of all elements that do not pass a given truth test.
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.
in
EnumeratesValues at line 891
EnumeratesValues
tap(callable $callback)
Pass the collection to the given callback and then return it.
at line 1776
Enumerable
unique(callable|int|string|null $key = null, bool $strict = false)
Return only unique items from the collection array.
in
EnumeratesValues at line 923
EnumeratesValues
uniqueStrict(callable|string|null $key = null)
Return only unique items from the collection array using strict comparison.
in
EnumeratesValues at line 933
Collection
collect()
Collect the values into a collection.
in
EnumeratesValues at line 943
array
toArray()
Get the collection of items as a plain array.
in
EnumeratesValues at line 953
array
jsonSerialize()
Convert the object into something JSON serializable.
in
EnumeratesValues at line 971
string
toJson(int $options = 0)
Get the collection of items as JSON.
in
EnumeratesValues at line 981
string
toPrettyJson(int $options = 0)
Get the collection of items as pretty print formatted JSON.
in
EnumeratesValues at line 989
CachingIterator
getCachingIterator(int $flags = CachingIterator::CALL_TOSTRING)
Get a CachingIterator instance.
in
EnumeratesValues at line 998
string
__toString()
Convert the collection to its string representation.
in
EnumeratesValues at line 1010
EnumeratesValues
escapeWhenCastingToString(bool $escape = true)
Indicate that the model's string representation should be escaped when __toString is invoked.
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.
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.
in
EnumeratesValues at line 1046
mixed
__get(string $key)
Dynamically access collection proxies.
in
EnumeratesValues at line 1060
protected array
getArrayableItems(mixed $items)
Results array of items from Collection or Arrayable.
in
EnumeratesValues at line 1070
protected callable
operatorForWhere(callable|string|null $key, mixed $operator = null, mixed $value = null)
Get an operator checker callback.
in
EnumeratesValues at line 1124
protected bool
useAsCallable(mixed $value)
Determine if the given value is callable, but not a string.
in
EnumeratesValues at line 1132
protected callable
valueRetriever(callable|int|string|null $value)
Get a value retrieving callback.
in
EnumeratesValues at line 1146
protected Closure
equality(mixed $value)
Make a function to check an item's equality.
in
EnumeratesValues at line 1154
protected Closure
negate(Closure $callback)
Make a function using another function, by negating its result.
in
EnumeratesValues at line 1164
protected Closure
identity()
Make a function that returns what's passed to it.
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.
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.
in
Macroable at line 61
static bool
hasMacro(string $name)
Check if macro is registered.
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.
in
Macroable at line 83
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
in
Macroable at line 108
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
at line 61
__construct(mixed $source = null)
Create a new lazy collection instance.
at line 85
protected LazyCollection
newInstance(mixed $items = [])
Create a new instance of the collection.
at line 111
static Enumerable
range(int $from, int $to, int $step = 1, mixed ...$args)
Create a collection with the given range.
at line 166
array
all()
Get all items in the enumerable.
at line 180
LazyCollection
eager()
Eager load all items into a new lazy collection backed by an array.
at line 190
LazyCollection
remember()
Cache values as they're enumerated.
at line 228
float|int|null
median(string|array|null $key = null)
Get the median of a given key.
at line 239
array|null
mode(string|array|null $key = null)
Get the mode of a given key.
at line 249
Collection|Enumerable
collapse()
Collapse the collection of items into a single array.
at line 267
LazyCollection
collapseWithKeys()
Collapse the collection of items into a single array while preserving its keys.
at line 285
bool
contains(mixed $key, mixed $operator = null, mixed $value = null)
Determine if an item exists in the enumerable.
at line 315
bool
containsStrict(mixed $key, mixed $value = null)
Determine if an item exists, using strict comparison.
at line 339
bool
doesntContain(mixed $key, mixed $operator = null, mixed $value = null)
Determine if an item is not contained in the enumerable.
at line 347
bool
doesntContainStrict(mixed $key, mixed $operator = null, mixed $value = null)
Determine if an item is not contained in the enumerable, using strict comparison.
at line 361
Enumerable
crossJoin(Arrayable|iterable ...$arrays)
Cross join with the given lists, returning all possible permutations.
at line 373
Collection|Enumerable
countBy(callable|string|null $countBy = null)
Count the number of items in the collection by a field or using a callback.
at line 397
Enumerable
diff(mixed $items)
Get the items that are not present in the given items.
at line 403
Enumerable
diffUsing(mixed $items, callable $callback)
Get the items that are not present in the given items, using the callback.
at line 409
Enumerable
diffAssoc(Arrayable|iterable $items)
Get the items whose keys and values are not present in the given items.
at line 415
Enumerable
diffAssocUsing(Arrayable|iterable $items, callable $callback)
Get the items whose keys and values are not present in the given items, using the callback.
at line 421
Enumerable
diffKeys(Arrayable|iterable $items)
Get the items whose keys are not present in the given items.
at line 427
Enumerable
diffKeysUsing(Arrayable|iterable $items, callable $callback)
Get the items whose keys are not present in the given items, using the callback.
at line 436
Collection|Enumerable
duplicates(callable|string|null $callback = null, bool $strict = false)
Retrieve duplicate items from the collection.
at line 446
Collection|Enumerable
duplicatesStrict(callable|string|null $callback = null)
Retrieve duplicate items from the collection using strict comparison.
at line 453
Enumerable
except(mixed $keys)
Get all items except for those with the specified keys.
at line 464
Enumerable
filter(callable|null $callback = null)
Run a filter over each of the items.
at line 488
mixed
first(callable|null $callback = null, mixed $default = null)
Get the first item from the enumerable passing the given truth test.
at line 514
Collection|Enumerable
flatten(int|float $depth = INF)
Get a flattened list of the items in the collection.
at line 536
Collection|Enumerable
flip()
Flip the items in the collection.
at line 556
mixed
get(mixed $key, mixed $default = null)
Get an item by key.
at line 586
Collection|Enumerable
groupBy(callable|array|string $groupBy, bool $preserveKeys = false)
Group an associative array by a field or using a callback.
at line 602
Enumerable
keyBy(callable|array|string $keyBy)
Key an associative array by a field or using a callback.
at line 625
bool
has(mixed $key)
Determine if an item exists in the collection by key.
at line 647
bool
hasAny(mixed $key)
Determine if any of the keys exist in the collection.
at line 665
string
implode(callable|string|null $value, string|null $glue = null)
Concatenate values of a given key as a string.
at line 670
Enumerable
intersect(mixed $items)
Intersect the collection with the given items.
at line 676
Enumerable
intersectUsing(mixed $items, callable $callback)
Intersect the collection with the given items, using the callback.
at line 682
Enumerable
intersectAssoc(mixed $items)
Intersect the collection with the given items with additional index check.
at line 688
Enumerable
intersectAssocUsing(mixed $items, callable $callback)
Intersect the collection with the given items with additional index check, using the callback.
at line 694
Enumerable
intersectByKeys(mixed $items)
Intersect the collection with the given items by key.
at line 703
bool
isEmpty()
Determine if the items are empty or not.
at line 713
string
join(string $glue, string $finalGlue = '')
Join all items from the collection using a string. The final items can use a separate glue string.
at line 723
Collection|Enumerable
keys()
Get the keys of the collection items.
at line 741
mixed
last(callable|null $callback = null, mixed $default = null)
Get the last item from the collection.
at line 764
Collection|Enumerable
pluck(Closure|string|int|array|null $value, Closure|string|int|array|null $key = null)
Get the values of a given key.
at line 799
Collection|Enumerable
map(callable $callback)
Run a map over each of the items.
at line 832
Enumerable
mapToDictionary(callable $callback)
Run a dictionary map over the items.
The callback should return an associative array with a single key/value pair.
at line 868
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.
at line 917
Enumerable
merge(mixed $items)
Merge the collection with the given items.
at line 933
Enumerable
mergeRecursive(mixed $items)
Recursively merge the collection with the given items.
at line 945
LazyCollection
multiply(int $multiplier)
Multiply the items in the collection by the multiplier.
at line 959
Enumerable
combine(Arrayable|iterable $values)
Create a collection by using this collection for keys and another for its values.
at line 986
Enumerable
union(mixed $items)
Union the collection with the given items.
at line 999
Enumerable
nth(int $step, int $offset = 0)
Create a new collection consisting of every n-th element.
at line 1023
Enumerable
only(mixed $keys)
Get the items with the specified keys.
at line 1059
LazyCollection
select(mixed $keys)
Select specific values from the items within the collection.
at line 1116
Enumerable
concat(iterable $source)
Push all of the given items onto the collection.
at line 1131
mixed
random(callable|int|string|null $number = null, bool $preserveKeys = false)
Get one or a specified number of items randomly from the collection.
at line 1143
Enumerable
replace(mixed $items)
Replace the collection items with the given items.
at line 1164
Enumerable
replaceRecursive(mixed $items)
Recursively replace the collection items with the given items.
at line 1170
Enumerable
reverse()
Reverse items order.
at line 1182
mixed
search(mixed $value, bool $strict = false)
Search the collection for a given value and return the corresponding key if successful.
at line 1206
mixed
before(mixed $value, bool $strict = false)
Get the item before the given item.
at line 1234
mixed
after(mixed $value, bool $strict = false)
Get the item after the given item.
at line 1258
Enumerable
shuffle()
Shuffle the items in the collection.
at line 1274
Collection|Enumerable
sliding(int $size = 2, int $step = 1)
Create chunks representing a "sliding window" view of the items in the collection.
at line 1316
Enumerable
skip(int $count)
Skip the first {$count} items.
at line 1338
Enumerable
skipUntil(mixed $value)
Skip items in the collection until the given condition is met.
at line 1350
Enumerable
skipWhile(mixed $value)
Skip items in the collection while the given condition is met.
at line 1369
Enumerable
slice(int $offset, int|null $length = null)
Get a slice of items from the enumerable.
at line 1388
Enumerable
split(int $numberOfGroups)
Split a collection into a certain number of groups.
at line 1408
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.
at line 1427
bool
hasSole(callable|string|null $key = null, mixed $operator = null, mixed $value = null)
Determine if the collection contains a single item or a single item matching the given criteria.
at line 1448
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.
at line 1467
Enumerable
chunk(int $size, bool $preserveKeys = true)
Chunk the collection into chunks of the given size.
at line 1512
Enumerable
splitIn(int $numberOfGroups)
Split a collection into a certain number of groups, and fill the first groups completely.
at line 1527
Enumerable
chunkWhile(callable $callback)
Chunk the collection into chunks with a callback.
at line 1561
Enumerable
sort(callable|int|null $callback = null)
Sort through each item with a callback.
at line 1567
Enumerable
sortDesc(int $options = SORT_REGULAR)
Sort items in descending order.
at line 1573
Enumerable
sortBy(array|callable|int|string $callback, int $options = SORT_REGULAR, SortDirection|bool $descending = false)
Sort the collection using the given callback.
at line 1579
Enumerable
sortByDesc(array|callable|int|string $callback, int $options = SORT_REGULAR)
Sort the collection in descending order using the given callback.
at line 1585
Enumerable
sortKeys(int $options = SORT_REGULAR, SortDirection|bool $descending = false)
Sort the collection keys.
at line 1591
Enumerable
sortKeysDesc(int $options = SORT_REGULAR)
Sort the collection keys in descending order.
at line 1597
Enumerable
sortKeysUsing(callable $callback)
Sort the collection keys using a callback.
at line 1608
Enumerable
take(int $limit)
Take the first or last {$limit} items.
at line 1653
Enumerable
takeUntil(mixed $value)
Take items in the collection until the given condition is met.
at line 1675
LazyCollection
takeUntilTimeout(DateTimeInterface $timeout, callable|null $callback = null)
Take items in the collection until a given point in time, with an optional callback on timeout.
at line 1708
Enumerable
takeWhile(mixed $value)
Take items in the collection while the given condition is met.
at line 1722
LazyCollection
tapEach(callable $callback)
Pass each item in the collection to the given callback, lazily.
at line 1738
LazyCollection
throttle(float $seconds)
Throttle the values, releasing them at most once per the given seconds.
at line 1758
Enumerable
dot(int|float $depth = INF)
Flatten a multi-dimensional associative array with dots.
at line 1764
Enumerable
undot()
Convert a flatten "dot" notation array into an expanded array.
at line 1798
Enumerable
values()
Reset the keys on the underlying array.
at line 1812
LazyCollection
withHeartbeat(DateInterval|int $interval, callable $callback)
Run the given callback every time the interval has passed.
at line 1836
protected int
intervalSeconds(DateInterval $interval)
Get the total seconds from the given interval.
at line 1854
Collection|Enumerable
zip(Arrayable|iterable ...$items)
Zip the collection together with one or more arrays.
e.g. new LazyCollection([1, 2, 3])->zip([4, 5, 6]); => [[1, 4], [2, 5], [3, 6]]
at line 1879
Collection|Enumerable
pad(int $size, mixed $value)
Pad collection to the specified length with a value.
at line 1906
Traversable
getIterator()
Get the values iterator.
at line 1914
int
count()
Count the number of items in the collection.
at line 1932
protected Iterator
makeIterator(IteratorAggregate|Iterator|array|callable $source)
Make an iterator from the given source.
at line 1970
protected array
explodePluckParameters(Closure|string|int|array|null $value, Closure|string|int|array|null $key)
Explode the "value" and "key" arguments passed to "pluck".
at line 1984
protected LazyCollection
passthru(string $method, array $params)
Pass this lazy collection through a method on the collection class.
at line 1994
protected int
now()
Get the current time.
at line 2004
protected float
preciseNow()
Get the precise current time.
at line 2014
protected void
usleep(int $microseconds)
Sleep for the given amount of microseconds.
at line 2029
static void
flushState()
Flush all static state.