Methods |
public
|
__construct(mixed $source = null): void
Create a new lazy collection instance.
Create a new lazy collection instance.
|
#
|
public
static
|
range(int $from, int $to): static
Create a collection with the given range.
Create a collection with the given range.
Implements
|
#
|
public
|
all(): array
Get all items in the enumerable.
Get all items in the enumerable.
Implements
|
#
|
public
|
eager(): static
Eager load all items into a new lazy collection backed by an array.
Eager load all items into a new lazy collection backed by an array.
|
#
|
public
|
remember(): static
Cache values as they're enumerated.
Cache values as they're enumerated.
|
#
|
public
|
avg(callable|string|null $callback = null): mixed
Get the average value of a given key.
Get the average value of a given key.
Implements
|
#
|
public
|
median(string|array|null $key = null): mixed
Get the median of a given key.
Get the median of a given key.
Implements
|
#
|
public
|
mode(string|array|null $key = null): array|null
Get the mode of a given key.
Get the mode of a given key.
Implements
|
#
|
public
|
collapse(): static
Collapse the collection of items into a single array.
Collapse the collection of items into a single array.
Implements
|
#
|
public
|
contains(mixed $key, mixed $operator = null, mixed $value = null): bool
Determine if an item exists in the enumerable.
Determine if an item exists in the enumerable.
Implements
|
#
|
public
|
doesntContain(mixed $key, mixed $operator = null, mixed $value = null): bool
Determine if an item is not contained in the enumerable.
Determine if an item is not contained in the enumerable.
|
#
|
public
|
crossJoin(array ...$arrays): static
Cross join the given iterables, returning all possible permutations.
Cross join the given iterables, returning all possible permutations.
Implements
|
#
|
public
|
countBy(callable|string $countBy = null): static
Count the number of items in the collection by a field or using a callback.
Count the number of items in the collection by a field or using a callback.
Implements
|
#
|
public
|
diff(mixed $items): static
Get the items that are not present in the given items.
Get the items that are not present in the given items.
Implements
|
#
|
public
|
diffUsing(mixed $items, callable $callback): static
Get the items that are not present in the given items, using the callback.
Get the items that are not present in the given items, using the callback.
Implements
|
#
|
public
|
diffAssoc(mixed $items): static
Get the items whose keys and values are not present in the given items.
Get the items whose keys and values are not present in the given items.
Implements
|
#
|
public
|
diffAssocUsing(mixed $items, callable $callback): static
Get the items whose keys and values 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.
Implements
|
#
|
public
|
diffKeys(mixed $items): static
Get the items whose keys are not present in the given items.
Get the items whose keys are not present in the given items.
Implements
|
#
|
public
|
diffKeysUsing(mixed $items, callable $callback): static
Get the items whose keys 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.
Implements
|
#
|
public
|
duplicates(callable|string|null $callback = null, bool $strict = false): static
Retrieve duplicate items.
Retrieve duplicate items.
Implements
|
#
|
public
|
duplicatesStrict(callable|string|null $callback = null): static
Retrieve duplicate items using strict comparison.
Retrieve duplicate items using strict comparison.
Implements
|
#
|
public
|
except(mixed $keys): static
Get all items except for those with the specified keys.
Get all items except for those with the specified keys.
Implements
|
#
|
public
|
filter(callable|null $callback = null): static
Run a filter over each of the items.
Run a filter over each of the items.
Implements
|
#
|
public
|
first(callable|null $callback = null, mixed $default = null): mixed
Get the first item from the enumerable passing the given truth test.
Get the first item from the enumerable passing the given truth test.
Implements
|
#
|
public
|
flatten(int $depth = INF): static
Get a flattened list of the items in the collection.
Get a flattened list of the items in the collection.
Implements
|
#
|
public
|
flip(): static
Flip the items in the collection.
Flip the items in the collection.
Implements
|
#
|
public
|
get(mixed $key, mixed $default = null): mixed
Get an item by key.
|
#
|
public
|
groupBy(array|callable|string $groupBy, bool $preserveKeys = false): static
Group an associative array by a field or using a callback.
Group an associative array by a field or using a callback.
Implements
|
#
|
public
|
keyBy(callable|string $keyBy): static
Key an associative array by a field or using a callback.
Key an associative array by a field or using a callback.
Implements
|
#
|
public
|
has(mixed $key): bool
Determine if an item exists in the collection by key.
Determine if an item exists in the collection by key.
Implements
|
#
|
public
|
hasAny(mixed $key): bool
Determine if any of the keys exist in the collection.
Determine if any of the keys exist in the collection.
|
#
|
public
|
implode(string $value, string|null $glue = null): string
Concatenate values of a given key as a string.
Concatenate values of a given key as a string.
Implements
|
#
|
public
|
intersect(mixed $items): static
Intersect the collection with the given items.
Intersect the collection with the given items.
Implements
|
#
|
public
|
intersectByKeys(mixed $items): static
Intersect the collection with the given items by key.
Intersect the collection with the given items by key.
Implements
|
#
|
public
|
isEmpty(): bool
Determine if the items are empty or not.
Determine if the items are empty or not.
Implements
|
#
|
public
|
containsOneItem(): bool
Determine if the collection contains a single item.
Determine if the collection contains a single item.
|
#
|
public
|
join(string $glue, string $finalGlue = ''): string
Join all items from the collection using a string. The final items can use a separate glue string.
Join all items from the collection using a string. The final items can use a separate glue string.
Implements
|
#
|
public
|
keys(): static
Get the keys of the collection items.
Get the keys of the collection items.
Implements
|
#
|
public
|
last(callable|null $callback = null, mixed $default = null): mixed
Get the last item from the collection.
Get the last item from the collection.
Implements
|
#
|
public
|
pluck(string|array $value, string|null $key = null): static
Get the values of a given key.
Get the values of a given key.
Implements
|
#
|
public
|
map(callable $callback): static
Run a map over each of the items.
Run a map over each of the items.
Implements
|
#
|
public
|
mapToDictionary(callable $callback): static
Run a dictionary map over the items.
Run a dictionary map over the items.
The callback should return an associative array with a single key/value pair.
Implements
|
#
|
public
|
mapWithKeys(callable $callback): static
Run an associative map over each of the items.
Run an associative map over each of the items.
The callback should return an associative array with a single key/value pair.
Implements
|
#
|
public
|
merge(mixed $items): static
Merge the collection with the given items.
Merge the collection with the given items.
Implements
|
#
|
public
|
mergeRecursive(mixed $items): static
Recursively merge the collection with the given items.
Recursively merge the collection with the given items.
Implements
|
#
|
public
|
combine(mixed $values): static
Create a collection by using this collection for keys and another for its values.
Create a collection by using this collection for keys and another for its values.
Implements
|
#
|
public
|
union(mixed $items): static
Union the collection with the given items.
Union the collection with the given items.
Implements
|
#
|
public
|
nth(int $step, int $offset = 0): static
Create a new collection consisting of every n-th element.
Create a new collection consisting of every n-th element.
Implements
|
#
|
public
|
only(mixed $keys): static
Get the items with the specified keys.
Get the items with the specified keys.
Implements
|
#
|
public
|
concat(iterable $source): static
Push all of the given items onto the collection.
Push all of the given items onto the collection.
Implements
|
#
|
public
|
random(int|null $number = null): static|mixed
Get one or a specified number of items randomly from the collection.
Get one or a specified number of items randomly from the collection.
Throws
Implements
|
#
|
public
|
replace(mixed $items): static
Replace the collection items with the given items.
Replace the collection items with the given items.
Implements
|
#
|
public
|
replaceRecursive(mixed $items): static
Recursively replace the collection items with the given items.
Recursively replace the collection items with the given items.
Implements
|
#
|
public
|
reverse(): static
Reverse items order.
|
#
|
public
|
search(mixed $value, bool $strict = false): mixed
Search the collection for a given value and return the corresponding key if successful.
Search the collection for a given value and return the corresponding key if successful.
Implements
|
#
|
public
|
shuffle(int|null $seed = null): static
Shuffle the items in the collection.
Shuffle the items in the collection.
Implements
|
#
|
public
|
sliding(int $size = 2, int $step = 1): static
Create chunks representing a "sliding window" view of the items in the collection.
Create chunks representing a "sliding window" view of the items in the collection.
|
#
|
public
|
skip(int $count): static
Skip the first {$count} items.
Skip the first {$count} items.
Implements
|
#
|
public
|
skipUntil(mixed $value): static
Skip items in the collection until the given condition is met.
Skip items in the collection until the given condition is met.
Implements
|
#
|
public
|
skipWhile(mixed $value): static
Skip items in the collection while the given condition is met.
Skip items in the collection while the given condition is met.
Implements
|
#
|
public
|
slice(int $offset, int|null $length = null): static
Get a slice of items from the enumerable.
Get a slice of items from the enumerable.
Implements
|
#
|
public
|
split(int $numberOfGroups): static
Split a collection into a certain number of groups.
Split a collection into a certain number of groups.
Implements
|
#
|
public
|
sole(mixed $key = null, mixed $operator = null, mixed $value = null): mixed
Get the first item in the collection, but only if exactly one item exists. Otherwise, throw an exception.
Get the first item in the collection, but only if exactly one item exists. Otherwise, throw an exception.
Throws
|
#
|
public
|
firstOrFail(mixed $key = null, mixed $operator = null, mixed $value = null): mixed
Get the first item in the collection but throw an exception if no matching items exist.
Get the first item in the collection but throw an exception if no matching items exist.
Throws
|
#
|
public
|
chunk(int $size): static
Chunk the collection into chunks of the given size.
Chunk the collection into chunks of the given size.
Implements
|
#
|
public
|
splitIn(int $numberOfGroups): static
Split a collection into a certain number of groups, and fill the first groups completely.
Split a collection into a certain number of groups, and fill the first groups completely.
|
#
|
public
|
chunkWhile(callable $callback): static
Chunk the collection into chunks with a callback.
Chunk the collection into chunks with a callback.
Implements
|
#
|
public
|
sort(callable|null|int $callback = null): static
Sort through each item with a callback.
Sort through each item with a callback.
Implements
|
#
|
public
|
sortDesc(int $options = SORT_REGULAR): static
Sort items in descending order.
Sort items in descending order.
Implements
|
#
|
public
|
sortBy(callable|string $callback, int $options = SORT_REGULAR, bool $descending = false): static
Sort the collection using the given callback.
Sort the collection using the given callback.
Implements
|
#
|
public
|
sortByDesc(callable|string $callback, int $options = SORT_REGULAR): static
Sort the collection in descending order using the given callback.
Sort the collection in descending order using the given callback.
Implements
|
#
|
public
|
sortKeys(int $options = SORT_REGULAR, bool $descending = false): static
Sort the collection keys.
Sort the collection keys.
Implements
|
#
|
public
|
sortKeysDesc(int $options = SORT_REGULAR): static
Sort the collection keys in descending order.
Sort the collection keys in descending order.
Implements
|
#
|
public
|
sortKeysUsing(callable $callback): static
Sort the collection keys using a callback.
Sort the collection keys using a callback.
|
#
|
public
|
take(int $limit): static
Take the first or last {$limit} items.
Take the first or last {$limit} items.
Implements
|
#
|
public
|
takeUntil(mixed $value): static
Take items in the collection until the given condition is met.
Take items in the collection until the given condition is met.
Implements
|
#
|
public
|
takeUntilTimeout(DateTimeInterface $timeout): static
Take items in the collection until a given point in time.
Take items in the collection until a given point in time.
|
#
|
public
|
takeWhile(mixed $value): static
Take items in the collection while the given condition is met.
Take items in the collection while the given condition is met.
Implements
|
#
|
public
|
tapEach(callable $callback): static
Pass each item in the collection to the given callback, lazily.
Pass each item in the collection to the given callback, lazily.
|
#
|
public
|
undot(): static
Convert a flatten "dot" notation array into an expanded array.
Convert a flatten "dot" notation array into an expanded array.
|
#
|
public
|
unique(string|callable|null $key = null, bool $strict = false): static
Return only unique items from the collection array.
Return only unique items from the collection array.
Implements
|
#
|
public
|
values(): static
Reset the keys on the underlying array.
Reset the keys on the underlying array.
Implements
|
#
|
public
|
zip(mixed ...$items): static
Zip the collection together with one or more arrays.
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]]
Implements
|
#
|
public
|
pad(int $size, mixed $value): static
Pad collection to the specified length with a value.
Pad collection to the specified length with a value.
Implements
|
#
|
public
|
getIterator(): Traversable
Get the values iterator.
|
#
|
public
|
count(): int
Count the number of items in the collection.
Count the number of items in the collection.
Implements
|
#
|