Methods |
public
static
|
make(mixed $items = []): static
Create a new collection instance if the value isn't one already.
Create a new collection instance if the value isn't one already.
|
#
|
public
static
|
times(int $number, callable|null $callback = null): static
Create a new instance by invoking the callback a given amount of times.
Create a new instance by invoking the callback a given amount of times.
|
#
|
public
static
|
range(int $from, int $to): static
Create a collection with the given range.
Create a collection with the given range.
Implemented by
|
#
|
public
static
|
wrap(mixed $value): static
Wrap the given value in a collection if applicable.
Wrap the given value in a collection if applicable.
|
#
|
public
static
|
unwrap(array|static $value): array
Get the underlying items from the given collection if applicable.
Get the underlying items from the given collection if applicable.
|
#
|
public
static
|
empty(): static
Create a new instance with no items.
Create a new instance with no items.
|
#
|
public
|
all(): array
Get all items in the enumerable.
Get all items in the enumerable.
Implemented by
|
#
|
public
|
average(callable|string|null $callback = null): mixed
Alias for the "avg" method.
Alias for the "avg" method.
|
#
|
public
|
median(string|array|null $key = null): mixed
Get the median of a given key.
Get the median of a given key.
Implemented by
|
#
|
public
|
mode(string|array|null $key = null): array|null
Get the mode of a given key.
Get the mode of a given key.
Implemented by
|
#
|
public
|
collapse(): static
Collapse the items into a single enumerable.
Collapse the items into a single enumerable.
Implemented by
|
#
|
public
|
some(mixed $key, mixed $operator = null, mixed $value = null): bool
Alias for the "contains" method.
Alias for the "contains" method.
|
#
|
public
|
containsStrict(mixed $key, mixed $value = null): bool
Determine if an item exists, using strict comparison.
Determine if an item exists, using strict comparison.
|
#
|
public
|
avg(callable|string|null $callback = null): mixed
Get the average value of a given key.
Get the average value of a given key.
Implemented by
|
#
|
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.
Implemented by
|
#
|
public
|
crossJoin(mixed ...$lists): static
Cross join with the given lists, returning all possible permutations.
Cross join with the given lists, returning all possible permutations.
Implemented by
|
#
|
public
|
dd(mixed ...$args): void
Dump the collection and end the script.
Dump the collection and end the script.
|
#
|
public
|
dump(): $this
Dump the collection.
|
#
|
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.
Implemented by
|
#
|
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.
Implemented by
|
#
|
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.
Implemented by
|
#
|
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.
Implemented by
|
#
|
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.
Implemented by
|
#
|
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.
Implemented by
|
#
|
public
|
duplicates(callable|string|null $callback = null, bool $strict = false): static
Retrieve duplicate items.
Retrieve duplicate items.
Implemented by
|
#
|
public
|
duplicatesStrict(callable|string|null $callback = null): static
Retrieve duplicate items using strict comparison.
Retrieve duplicate items using strict comparison.
Implemented by
|
#
|
public
|
each(callable $callback): $this
Execute a callback over each item.
Execute a callback over each item.
|
#
|
public
|
eachSpread(callable $callback): static
Execute a callback over each nested chunk of items.
Execute a callback over each nested chunk of items.
|
#
|
public
|
every(string|callable $key, mixed $operator = null, mixed $value = null): bool
Determine if all items pass the given truth test.
Determine if all items pass the given truth test.
|
#
|
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.
Implemented by
|
#
|
public
|
filter(callable|null $callback = null): static
Run a filter over each of the items.
Run a filter over each of the items.
Implemented by
|
#
|
public
|
when(bool $value, callable $callback, callable|null $default = null): static|mixed
Apply the callback if the value is truthy.
Apply the callback if the value is truthy.
|
#
|
public
|
whenEmpty(callable $callback, callable|null $default = null): static|mixed
Apply the callback if the collection is empty.
Apply the callback if the collection is empty.
|
#
|
public
|
whenNotEmpty(callable $callback, callable|null $default = null): static|mixed
Apply the callback if the collection is not empty.
Apply the callback if the collection is not empty.
|
#
|
public
|
unless(bool $value, callable $callback, callable|null $default = null): static|mixed
Apply the callback if the value is falsy.
Apply the callback if the value is falsy.
|
#
|
public
|
unlessEmpty(callable $callback, callable|null $default = null): static|mixed
Apply the callback unless the collection is empty.
Apply the callback unless the collection is empty.
|
#
|
public
|
unlessNotEmpty(callable $callback, callable|null $default = null): static|mixed
Apply the callback unless the collection is not empty.
Apply the callback unless the collection is not empty.
|
#
|
public
|
where(string $key, mixed $operator = null, mixed $value = null): static
Filter items by the given key value pair.
Filter items by the given key value pair.
|
#
|
public
|
whereNull(string|null $key = null): static
Filter items where the value for the given key is null.
Filter items where the value for the given key is null.
|
#
|
public
|
whereNotNull(string|null $key = null): static
Filter items where the value for the given key is not null.
Filter items where the value for the given key is not null.
|
#
|
public
|
whereStrict(string $key, mixed $value): static
Filter items by the given key value pair using strict comparison.
Filter items by the given key value pair using strict comparison.
|
#
|
public
|
whereIn(string $key, mixed $values, bool $strict = false): static
Filter items by the given key value pair.
Filter items by the given key value pair.
|
#
|
public
|
whereInStrict(string $key, mixed $values): static
Filter items by the given key value pair using strict comparison.
Filter items by the given key value pair using strict comparison.
|
#
|
public
|
whereBetween(string $key, array $values): static
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 between the given values.
|
#
|
public
|
whereNotBetween(string $key, array $values): static
Filter items such that the value of the given key is not between the given values.
Filter items such that the value of the given key is not between the given values.
|
#
|
public
|
whereNotIn(string $key, mixed $values, bool $strict = false): static
Filter items by the given key value pair.
Filter items by the given key value pair.
|
#
|
public
|
whereNotInStrict(string $key, mixed $values): static
Filter items by the given key value pair using strict comparison.
Filter items by the given key value pair using strict comparison.
|
#
|
public
|
whereInstanceOf(string|string[] $type): static
Filter the items, removing any items that don't match the given type(s).
Filter the items, removing any items that don't match the given type(s).
|
#
|
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.
Implemented by
|
#
|
public
|
firstWhere(string $key, mixed $operator = null, mixed $value = null): mixed
Get the first item by the given key value pair.
Get the first item by the given key value pair.
|
#
|
public
|
flatten(int $depth = INF): static
Get a flattened array of the items in the collection.
Get a flattened array of the items in the collection.
Implemented by
|
#
|
public
|
flip(): static
Flip the values with their keys.
Flip the values with their keys.
Implemented by
|
#
|
public
|
get(mixed $key, mixed $default = null): mixed
Get an item from the collection by key.
Get an item from the collection by key.
Implemented by
|
#
|
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.
Implemented by
|
#
|
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.
Implemented by
|
#
|
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.
Implemented by
|
#
|
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.
Implemented by
|
#
|
public
|
intersect(mixed $items): static
Intersect the collection with the given items.
Intersect the collection with the given items.
Implemented by
|
#
|
public
|
intersectByKeys(mixed $items): static
Intersect the collection with the given items by key.
Intersect the collection with the given items by key.
Implemented by
|
#
|
public
|
isEmpty(): bool
Determine if the collection is empty or not.
Determine if the collection is empty or not.
Implemented by
|
#
|
public
|
isNotEmpty(): bool
Determine if the collection is not empty.
Determine if the collection is not empty.
|
#
|
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.
Implemented by
|
#
|
public
|
keys(): static
Get the keys of the collection items.
Get the keys of the collection items.
Implemented by
|
#
|
public
|
last(callable|null $callback = null, mixed $default = null): mixed
Get the last item from the collection.
Get the last item from the collection.
Implemented by
|
#
|
public
|
map(callable $callback): static
Run a map over each of the items.
Run a map over each of the items.
Implemented by
|
#
|
public
|
mapSpread(callable $callback): static
Run a map over each nested chunk of items.
Run a map over each nested chunk of items.
|
#
|
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.
Implemented by
|
#
|
public
|
mapToGroups(callable $callback): static
Run a grouping map over the items.
Run a grouping map over the items.
The callback should return an associative array with a single key/value pair.
|
#
|
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.
Implemented by
|
#
|
public
|
flatMap(callable $callback): static
Map a collection and flatten the result by a single level.
Map a collection and flatten the result by a single level.
|
#
|
public
|
mapInto(string $class): static
Map the values into a new class.
Map the values into a new class.
|
#
|
public
|
merge(mixed $items): static
Merge the collection with the given items.
Merge the collection with the given items.
Implemented by
|
#
|
public
|
mergeRecursive(mixed $items): static
Recursively merge the collection with the given items.
Recursively merge the collection with the given items.
Implemented by
|
#
|
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.
Implemented by
|
#
|
public
|
union(mixed $items): static
Union the collection with the given items.
Union the collection with the given items.
Implemented by
|
#
|
public
|
min(callable|string|null $callback = null): mixed
Get the min value of a given key.
Get the min value of a given key.
|
#
|
public
|
max(callable|string|null $callback = null): mixed
Get the max value of a given key.
Get the max value of a given key.
|
#
|
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.
Implemented by
|
#
|
public
|
only(mixed $keys): static
Get the items with the specified keys.
Get the items with the specified keys.
Implemented by
|
#
|
public
|
forPage(int $page, int $perPage): static
"Paginate" the collection by slicing it into a smaller collection.
"Paginate" the collection by slicing it into a smaller collection.
|
#
|
public
|
partition(callable|string $key, mixed $operator = null, mixed $value = null): static
Partition the collection into two arrays using the given callback or key.
Partition the collection into two arrays using the given callback or key.
|
#
|
public
|
concat(iterable $source): static
Push all of the given items onto the collection.
Push all of the given items onto the collection.
Implemented by
|
#
|
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
Implemented by
|
#
|
public
|
reduce(callable $callback, mixed $initial = null): mixed
Reduce the collection to a single value.
Reduce the collection to a single value.
|
#
|
public
|
replace(mixed $items): static
Replace the collection items with the given items.
Replace the collection items with the given items.
Implemented by
|
#
|
public
|
replaceRecursive(mixed $items): static
Recursively replace the collection items with the given items.
Recursively replace the collection items with the given items.
Implemented by
|
#
|
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.
Implemented by
|
#
|
public
|
shuffle(int|null $seed = null): static
Shuffle the items in the collection.
Shuffle the items in the collection.
Implemented by
|
#
|
public
|
skip(int $count): static
Skip the first {$count} items.
Skip the first {$count} items.
Implemented by
|
#
|
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.
Implemented by
|
#
|
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.
Implemented by
|
#
|
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.
Implemented by
|
#
|
public
|
split(int $numberOfGroups): static
Split a collection into a certain number of groups.
Split a collection into a certain number of groups.
Implemented by
|
#
|
public
|
chunk(int $size): static
Chunk the collection into chunks of the given size.
Chunk the collection into chunks of the given size.
Implemented by
|
#
|
public
|
chunkWhile(callable $callback): static
Chunk the collection into chunks with a callback.
Chunk the collection into chunks with a callback.
Implemented by
|
#
|
public
|
sort(callable|null|int $callback = null): static
Sort through each item with a callback.
Sort through each item with a callback.
Implemented by
|
#
|
public
|
sortDesc(int $options = SORT_REGULAR): static
Sort items in descending order.
Sort items in descending order.
Implemented by
|
#
|
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.
Implemented by
|
#
|
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.
Implemented by
|
#
|
public
|
sortKeys(int $options = SORT_REGULAR, bool $descending = false): static
Sort the collection keys.
Sort the collection keys.
Implemented by
|
#
|
public
|
sortKeysDesc(int $options = SORT_REGULAR): static
Sort the collection keys in descending order.
Sort the collection keys in descending order.
Implemented by
|
#
|
public
|
sum(callable|string|null $callback = null): mixed
Get the sum of the given values.
Get the sum of the given values.
|
#
|
public
|
take(int $limit): static
Take the first or last {$limit} items.
Take the first or last {$limit} items.
Implemented by
|
#
|
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.
Implemented by
|
#
|
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.
Implemented by
|
#
|
public
|
tap(callable $callback): $this
Pass the collection to the given callback and then return it.
Pass the collection to the given callback and then return it.
|
#
|
public
|
pipe(callable $callback): mixed
Pass the enumerable to the given callback and return the result.
Pass the enumerable to the given callback and return the result.
|
#
|
public
|
pluck(string|array $value, string|null $key = null): static
Get the values of a given key.
Get the values of a given key.
Implemented by
|
#
|
public
|
reject(callable|mixed $callback = true): static
Create a collection of all elements that do not pass a given truth test.
Create a collection of all elements that do not pass a given truth test.
|
#
|
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.
Implemented by
|
#
|
public
|
uniqueStrict(string|callable|null $key = null): static
Return only unique items from the collection array using strict comparison.
Return only unique items from the collection array using strict comparison.
|
#
|
public
|
values(): static
Reset the keys on the underlying array.
Reset the keys on the underlying array.
Implemented by
|
#
|
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.
Implemented by
|
#
|
public
|
countBy(callable|null $callback = null): static
Count the number of items in the collection using a given truth test.
Count the number of items in the collection using a given truth test.
Implemented by
|
#
|
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 Collection([1, 2, 3])->zip([4, 5, 6]);
=> [[1, 4], [2, 5], [3, 6]]
Implemented by
|
#
|
public
|
collect(): Collection
Collect the values into a collection.
Collect the values into a collection.
|
#
|
public
|
__toString(): string
Convert the collection to its string representation.
Convert the collection to its string representation.
|
#
|
public
static
|
proxy(string $method): void
Add a method to the list of proxied methods.
Add a method to the list of proxied methods.
|
#
|
public
|
__get(string $key): mixed
Dynamically access collection proxies.
Dynamically access collection proxies.
Throws
|
#
|