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
|
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
static
|
times(int $number, callable|null $callback = null): static
Create a new collection by invoking the callback a given amount of times.
Create a new collection by invoking the callback a given amount of times.
|
#
|
public
|
average(callable|string|null $callback = null): mixed
Alias for the "avg" method.
Alias for the "avg" method.
|
#
|
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
|
dd(mixed ...$args): void
Dump the items and end the script.
Dump the items and end the script.
|
#
|
public
|
dump(): $this
Dump the items.
|
#
|
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
|
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
|
isNotEmpty(): bool
Determine if the collection is not empty.
Determine if the collection is not empty.
|
#
|
public
|
mapSpread(callable $callback): static
Run a map over each nested chunk of items.
Run a map over each nested chunk of items.
|
#
|
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
|
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
|
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
|
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
|
sum(callable|string|null $callback = null): mixed
Get the sum of the given values.
Get the sum of the given values.
|
#
|
public
|
when(bool|mixed $value, callable|null $callback = null, 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
|
pipe(callable $callback): mixed
Pass the collection to the given callback and return the result.
Pass the collection to the given callback and return the result.
|
#
|
public
|
pipeInto(string $class): mixed
Pass the collection into a new class.
Pass the collection into a new class.
|
#
|
public
|
pipeThrough(array<callable> $pipes): mixed
Pass the collection through a series of callable pipes and return the result.
Pass the collection through a series of callable pipes and return the result.
|
#
|
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
|
reduce(callable $callback, mixed $initial = null): mixed
Reduce the collection to a single value.
Reduce the collection to a single value.
|
#
|
public
|
reduceMany(callable $callback, mixed ...$initial): array
Reduce the collection to multiple aggregate values.
Reduce the collection to multiple aggregate values.
Deprecated
Use "reduceSpread" instead
Throws
|
#
|
public
|
reduceSpread(callable $callback, mixed ...$initial): array
Reduce the collection to multiple aggregate values.
Reduce the collection to multiple aggregate values.
Throws
|
#
|
public
|
reduceWithKeys(callable $callback, mixed $initial = null): mixed
Reduce an associative collection to a single value.
Reduce an associative collection to a single value.
|
#
|
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
|
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
|
collect(): Collection
Collect the values into a collection.
Collect the values into a collection.
|
#
|
public
|
toArray(): array
Get the collection of items as a plain array.
Get the collection of items as a plain array.
|
#
|
public
|
jsonSerialize(): array
Convert the object into something JSON serializable.
Convert the object into something JSON serializable.
|
#
|
public
|
toJson(int $options = 0): string
Get the collection of items as JSON.
Get the collection of items as JSON.
|
#
|
public
|
getCachingIterator(int $flags = CachingIterator::CALL_TOSTRING): CachingIterator
Get a CachingIterator instance.
Get a CachingIterator instance.
|
#
|
public
|
__toString(): string
Convert the collection to its string representation.
Convert the collection to its string representation.
|
#
|
public
|
escapeWhenCastingToString(bool $escape = true): $this
Indicate that the model's string representation should be escaped when __toString is invoked.
Indicate that the model's string representation should be escaped when __toString is invoked.
|
#
|
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
|
#
|