EnumeratesValues

trait EnumeratesValues (View source)

Properties

static protected array $proxies The methods that can be proxied.

Methods

static EnumeratesValues make(mixed $items = [])

Create a new collection instance if the value isn't one already.

static EnumeratesValues wrap(mixed $value)

Wrap the given value in a collection if applicable.

static array unwrap(array|EnumeratesValues $value)

Get the underlying items from the given collection if applicable.

mixed average(callable|string|null $callback = null)

Alias for the "avg" method.

bool some(mixed $key, mixed $operator = null, mixed $value = null)

Alias for the "contains" method.

bool containsStrict(mixed $key, mixed $value = null)

Determine if an item exists, using strict comparison.

void dd(mixed ...$args)

Dump the items and end the script.

$this dump()

Dump the items.

$this each(callable $callback)

Execute a callback over each item.

EnumeratesValues eachSpread(callable $callback)

Execute a callback over each nested chunk of items.

bool every(string|callable $key, mixed $operator = null, mixed $value = null)

Determine if all items pass the given truth test.

mixed firstWhere(string $key, mixed $operator = null, mixed $value = null)

Get the first item by the given key value pair.

bool isNotEmpty()

Determine if the collection is not empty.

EnumeratesValues mapSpread(callable $callback)

Run a map over each nested chunk of items.

EnumeratesValues mapToGroups(callable $callback)

Run a grouping map over the items.

EnumeratesValues flatMap(callable $callback)

Map a collection and flatten the result by a single level.

EnumeratesValues mapInto(string $class)

Map the values into a new class.

mixed min(callable|string|null $callback = null)

Get the min value of a given key.

mixed max(callable|string|null $callback = null)

Get the max value of a given key.

EnumeratesValues forPage(int $page, int $perPage)

"Paginate" the collection by slicing it into a smaller collection.

EnumeratesValues partition(callable|string $key, mixed $operator = null, mixed $value = null)

Partition the collection into two arrays using the given callback or key.

mixed sum(callable|string|null $callback = null)

Get the sum of the given values.

EnumeratesValues|mixed when(bool|mixed $value, callable $callback = null, callable $default = null)

Apply the callback if the value is truthy.

EnumeratesValues|mixed whenEmpty(callable $callback, callable $default = null)

Apply the callback if the collection is empty.

EnumeratesValues|mixed whenNotEmpty(callable $callback, callable $default = null)

Apply the callback if the collection is not empty.

EnumeratesValues|mixed unless(bool $value, callable $callback, callable $default = null)

Apply the callback if the value is falsy.

EnumeratesValues|mixed unlessEmpty(callable $callback, callable $default = null)

Apply the callback unless the collection is empty.

EnumeratesValues|mixed unlessNotEmpty(callable $callback, callable $default = null)

Apply the callback unless the collection is not empty.

EnumeratesValues where(string $key, mixed $operator = null, mixed $value = null)

Filter items by the given key value pair.

EnumeratesValues whereNull(string|null $key = null)

Filter items where the given key is not null.

EnumeratesValues whereNotNull(string|null $key = null)

Filter items where the given key is null.

EnumeratesValues whereStrict(string $key, mixed $value)

Filter items by the given key value pair using strict comparison.

EnumeratesValues whereIn(string $key, mixed $values, bool $strict = false)

Filter items by the given key value pair.

EnumeratesValues whereInStrict(string $key, mixed $values)

Filter items by the given key value pair using strict comparison.

EnumeratesValues whereBetween(string $key, array $values)

Filter items such that the value of the given key is between the given values.

EnumeratesValues whereNotBetween(string $key, array $values)

Filter items such that the value of the given key is not between the given values.

EnumeratesValues whereNotIn(string $key, mixed $values, bool $strict = false)

Filter items by the given key value pair.

EnumeratesValues whereNotInStrict(string $key, mixed $values)

Filter items by the given key value pair using strict comparison.

EnumeratesValues whereInstanceOf(string $type)

Filter the items, removing any items that don't match the given type.

mixed pipe(callable $callback)

Pass the collection to the given callback and return the result.

$this tap(callable $callback)

Pass the collection to the given callback and then return it.

EnumeratesValues reject(callable|mixed $callback = true)

Create a collection of all elements that do not pass a given truth test.

EnumeratesValues unique(string|callable|null $key = null, bool $strict = false)

Return only unique items from the collection array.

EnumeratesValues uniqueStrict(string|callable|null $key = null)

Return only unique items from the collection array using strict comparison.

EnumeratesValues until(mixed $value) deprecated

Take items in the collection until the given condition is met.

Collection collect()

Collect the values into a collection.

array toArray()

Get the collection of items as a plain array.

array jsonSerialize()

Convert the object into something JSON serializable.

string toJson(int $options = 0)

Get the collection of items as JSON.

CachingIterator getCachingIterator(int $flags = CachingIterator::CALL_TOSTRING)

Get a CachingIterator instance.

string __toString()

Convert the collection to its string representation.

static void proxy(string $method)

Add a method to the list of proxied methods.

mixed __get(string $key)

Dynamically access collection proxies.

array getArrayableItems(mixed $items)

Results array of items from Collection or Arrayable.

Closure operatorForWhere(string $key, string|null $operator = null, mixed $value = null)

Get an operator checker callback.

bool useAsCallable(mixed $value)

Determine if the given value is callable, but not a string.

callable valueRetriever(callable|string|null $value)

Get a value retrieving callback.

Closure equality(mixed $value)

Make a function to check an item's equality.

Closure negate(Closure $callback)

Make a function using another function, by negating its result.

Closure identity()

Make a function that returns what's passed to it.

Details

static EnumeratesValues make(mixed $items = [])

Create a new collection instance if the value isn't one already.

Parameters

mixed $items

Return Value

EnumeratesValues

static EnumeratesValues wrap(mixed $value)

Wrap the given value in a collection if applicable.

Parameters

mixed $value

Return Value

EnumeratesValues

static array unwrap(array|EnumeratesValues $value)

Get the underlying items from the given collection if applicable.

Parameters

array|EnumeratesValues $value

Return Value

array

mixed average(callable|string|null $callback = null)

Alias for the "avg" method.

Parameters

callable|string|null $callback

Return Value

mixed

bool some(mixed $key, mixed $operator = null, mixed $value = null)

Alias for the "contains" method.

Parameters

mixed $key
mixed $operator
mixed $value

Return Value

bool

bool containsStrict(mixed $key, mixed $value = null)

Determine if an item exists, using strict comparison.

Parameters

mixed $key
mixed $value

Return Value

bool

void dd(mixed ...$args)

Dump the items and end the script.

Parameters

mixed ...$args

Return Value

void

$this dump()

Dump the items.

Return Value

$this

$this each(callable $callback)

Execute a callback over each item.

Parameters

callable $callback

Return Value

$this

EnumeratesValues eachSpread(callable $callback)

Execute a callback over each nested chunk of items.

Parameters

callable $callback

Return Value

EnumeratesValues

bool every(string|callable $key, mixed $operator = null, mixed $value = null)

Determine if all items pass the given truth test.

Parameters

string|callable $key
mixed $operator
mixed $value

Return Value

bool

mixed firstWhere(string $key, mixed $operator = null, mixed $value = null)

Get the first item by the given key value pair.

Parameters

string $key
mixed $operator
mixed $value

Return Value

mixed

bool isNotEmpty()

Determine if the collection is not empty.

Return Value

bool

EnumeratesValues mapSpread(callable $callback)

Run a map over each nested chunk of items.

Parameters

callable $callback

Return Value

EnumeratesValues

EnumeratesValues mapToGroups(callable $callback)

Run a grouping map over the items.

The callback should return an associative array with a single key/value pair.

Parameters

callable $callback

Return Value

EnumeratesValues

EnumeratesValues flatMap(callable $callback)

Map a collection and flatten the result by a single level.

Parameters

callable $callback

Return Value

EnumeratesValues

EnumeratesValues mapInto(string $class)

Map the values into a new class.

Parameters

string $class

Return Value

EnumeratesValues

mixed min(callable|string|null $callback = null)

Get the min value of a given key.

Parameters

callable|string|null $callback

Return Value

mixed

mixed max(callable|string|null $callback = null)

Get the max value of a given key.

Parameters

callable|string|null $callback

Return Value

mixed

EnumeratesValues forPage(int $page, int $perPage)

"Paginate" the collection by slicing it into a smaller collection.

Parameters

int $page
int $perPage

Return Value

EnumeratesValues

EnumeratesValues partition(callable|string $key, mixed $operator = null, mixed $value = null)

Partition the collection into two arrays using the given callback or key.

Parameters

callable|string $key
mixed $operator
mixed $value

Return Value

EnumeratesValues

mixed sum(callable|string|null $callback = null)

Get the sum of the given values.

Parameters

callable|string|null $callback

Return Value

mixed

EnumeratesValues|mixed when(bool|mixed $value, callable $callback = null, callable $default = null)

Apply the callback if the value is truthy.

Parameters

bool|mixed $value
callable $callback
callable $default

Return Value

EnumeratesValues|mixed

EnumeratesValues|mixed whenEmpty(callable $callback, callable $default = null)

Apply the callback if the collection is empty.

Parameters

callable $callback
callable $default

Return Value

EnumeratesValues|mixed

EnumeratesValues|mixed whenNotEmpty(callable $callback, callable $default = null)

Apply the callback if the collection is not empty.

Parameters

callable $callback
callable $default

Return Value

EnumeratesValues|mixed

EnumeratesValues|mixed unless(bool $value, callable $callback, callable $default = null)

Apply the callback if the value is falsy.

Parameters

bool $value
callable $callback
callable $default

Return Value

EnumeratesValues|mixed

EnumeratesValues|mixed unlessEmpty(callable $callback, callable $default = null)

Apply the callback unless the collection is empty.

Parameters

callable $callback
callable $default

Return Value

EnumeratesValues|mixed

EnumeratesValues|mixed unlessNotEmpty(callable $callback, callable $default = null)

Apply the callback unless the collection is not empty.

Parameters

callable $callback
callable $default

Return Value

EnumeratesValues|mixed

EnumeratesValues where(string $key, mixed $operator = null, mixed $value = null)

Filter items by the given key value pair.

Parameters

string $key
mixed $operator
mixed $value

Return Value

EnumeratesValues

EnumeratesValues whereNull(string|null $key = null)

Filter items where the given key is not null.

Parameters

string|null $key

Return Value

EnumeratesValues

EnumeratesValues whereNotNull(string|null $key = null)

Filter items where the given key is null.

Parameters

string|null $key

Return Value

EnumeratesValues

EnumeratesValues whereStrict(string $key, mixed $value)

Filter items by the given key value pair using strict comparison.

Parameters

string $key
mixed $value

Return Value

EnumeratesValues

EnumeratesValues whereIn(string $key, mixed $values, bool $strict = false)

Filter items by the given key value pair.

Parameters

string $key
mixed $values
bool $strict

Return Value

EnumeratesValues

EnumeratesValues whereInStrict(string $key, mixed $values)

Filter items by the given key value pair using strict comparison.

Parameters

string $key
mixed $values

Return Value

EnumeratesValues

EnumeratesValues whereBetween(string $key, array $values)

Filter items such that the value of the given key is between the given values.

Parameters

string $key
array $values

Return Value

EnumeratesValues

EnumeratesValues whereNotBetween(string $key, array $values)

Filter items such that the value of the given key is not between the given values.

Parameters

string $key
array $values

Return Value

EnumeratesValues

EnumeratesValues whereNotIn(string $key, mixed $values, bool $strict = false)

Filter items by the given key value pair.

Parameters

string $key
mixed $values
bool $strict

Return Value

EnumeratesValues

EnumeratesValues whereNotInStrict(string $key, mixed $values)

Filter items by the given key value pair using strict comparison.

Parameters

string $key
mixed $values

Return Value

EnumeratesValues

EnumeratesValues whereInstanceOf(string $type)

Filter the items, removing any items that don't match the given type.

Parameters

string $type

Return Value

EnumeratesValues

mixed pipe(callable $callback)

Pass the collection to the given callback and return the result.

Parameters

callable $callback

Return Value

mixed

$this tap(callable $callback)

Pass the collection to the given callback and then return it.

Parameters

callable $callback

Return Value

$this

EnumeratesValues reject(callable|mixed $callback = true)

Create a collection of all elements that do not pass a given truth test.

Parameters

callable|mixed $callback

Return Value

EnumeratesValues

EnumeratesValues unique(string|callable|null $key = null, bool $strict = false)

Return only unique items from the collection array.

Parameters

string|callable|null $key
bool $strict

Return Value

EnumeratesValues

EnumeratesValues uniqueStrict(string|callable|null $key = null)

Return only unique items from the collection array using strict comparison.

Parameters

string|callable|null $key

Return Value

EnumeratesValues

EnumeratesValues until(mixed $value) deprecated

deprecated

Use the "takeUntil" method directly.

Take items in the collection until the given condition is met.

This is an alias to the "takeUntil" method.

Parameters

mixed $value

Return Value

EnumeratesValues

Collection collect()

Collect the values into a collection.

Return Value

Collection

array toArray()

Get the collection of items as a plain array.

Return Value

array

array jsonSerialize()

Convert the object into something JSON serializable.

Return Value

array

string toJson(int $options = 0)

Get the collection of items as JSON.

Parameters

int $options

Return Value

string

CachingIterator getCachingIterator(int $flags = CachingIterator::CALL_TOSTRING)

Get a CachingIterator instance.

Parameters

int $flags

Return Value

CachingIterator

string __toString()

Convert the collection to its string representation.

Return Value

string

static void proxy(string $method)

Add a method to the list of proxied methods.

Parameters

string $method

Return Value

void

mixed __get(string $key)

Dynamically access collection proxies.

Parameters

string $key

Return Value

mixed

Exceptions

Exception

protected array getArrayableItems(mixed $items)

Results array of items from Collection or Arrayable.

Parameters

mixed $items

Return Value

array

protected Closure operatorForWhere(string $key, string|null $operator = null, mixed $value = null)

Get an operator checker callback.

Parameters

string $key
string|null $operator
mixed $value

Return Value

Closure

protected bool useAsCallable(mixed $value)

Determine if the given value is callable, but not a string.

Parameters

mixed $value

Return Value

bool

protected callable valueRetriever(callable|string|null $value)

Get a value retrieving callback.

Parameters

callable|string|null $value

Return Value

callable

protected Closure equality(mixed $value)

Make a function to check an item's equality.

Parameters

mixed $value

Return Value

Closure

protected Closure negate(Closure $callback)

Make a function using another function, by negating its result.

Parameters

Closure $callback

Return Value

Closure

protected Closure identity()

Make a function that returns what's passed to it.

Return Value

Closure

© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/7.x/Illuminate/Support/Traits/EnumeratesValues.html