Enumerable
Methods
make ( $items ) : static
Create a new collection instance if the value isn't one already.
Parameters
- $items mixed
times ( $number , callable $callback ) : static
Create a new instance by invoking the callback a given amount of times.
Parameters
- $number int
- $callback callable|null
range ( $from , $to ) : static
Create a collection with the given range.
Parameters
- $from int
- $to int
wrap ( $value ) : static
Wrap the given value in a collection if applicable.
Parameters
- $value mixed
unwrap ( $value ) : array
Get the underlying items from the given collection if applicable.
Parameters
- $value array|static
empty ( ) : static
Create a new instance with no items.
all ( ) : array
Get all items in the enumerable.
average ( $callback ) : mixed
Alias for the "avg" method.
Parameters
- $callback callable|string|null
median ( $key ) : mixed
Get the median of a given key.
Parameters
- $key string|array|null
mode ( $key ) : array|null
Get the mode of a given key.
Parameters
- $key string|array|null
collapse ( ) : static
Collapse the items into a single enumerable.
some ( $key , $operator , $value ) : bool
Alias for the "contains" method.
Parameters
- $key mixed
- $operator mixed
- $value mixed
containsStrict ( $key , $value ) : bool
Determine if an item exists, using strict comparison.
Parameters
- $key mixed
- $value mixed
avg ( $callback ) : mixed
Get the average value of a given key.
Parameters
- $callback callable|string|null
contains ( $key , $operator , $value ) : bool
Determine if an item exists in the enumerable.
Parameters
- $key mixed
- $operator mixed
- $value mixed
crossJoin ( $lists ) : static
Cross join with the given lists, returning all possible permutations.
Parameters
- $lists mixed
dd ( $args ) : void
Dump the collection and end the script.
Parameters
- $args mixed
dump ( ) : $this
Dump the collection.
diff ( $items ) : static
Get the items that are not present in the given items.
Parameters
- $items mixed
diffUsing ( $items , callable $callback ) : static
Get the items that are not present in the given items, using the callback.
Parameters
- $items mixed
- $callback callable
diffAssoc ( $items ) : static
Get the items whose keys and values are not present in the given items.
Parameters
- $items mixed
diffAssocUsing ( $items , callable $callback ) : static
Get the items whose keys and values are not present in the given items, using the callback.
Parameters
- $items mixed
- $callback callable
diffKeys ( $items ) : static
Get the items whose keys are not present in the given items.
Parameters
- $items mixed
diffKeysUsing ( $items , callable $callback ) : static
Get the items whose keys are not present in the given items, using the callback.
Parameters
- $items mixed
- $callback callable
duplicates ( $callback , $strict ) : static
Retrieve duplicate items.
Parameters
- $callback callable|string|null
- $strict bool
duplicatesStrict ( $callback ) : static
Retrieve duplicate items using strict comparison.
Parameters
- $callback callable|string|null
each ( callable $callback ) : $this
Execute a callback over each item.
Parameters
- $callback callable
eachSpread ( callable $callback ) : static
Execute a callback over each nested chunk of items.
Parameters
- $callback callable
every ( $key , $operator , $value ) : bool
Determine if all items pass the given truth test.
Parameters
- $key string|callable
- $operator mixed
- $value mixed
except ( $keys ) : static
Get all items except for those with the specified keys.
Parameters
- $keys mixed
filter ( callable $callback ) : static
Run a filter over each of the items.
Parameters
- $callback callable|null
when ( $value , callable $callback , callable $default ) : static|mixed
Apply the callback if the value is truthy.
Parameters
- $value bool
- $callback callable
- $default callable|null
whenEmpty ( callable $callback , callable $default ) : static|mixed
Apply the callback if the collection is empty.
Parameters
- $callback callable
- $default callable|null
whenNotEmpty ( callable $callback , callable $default ) : static|mixed
Apply the callback if the collection is not empty.
Parameters
- $callback callable
- $default callable|null
unless ( $value , callable $callback , callable $default ) : static|mixed
Apply the callback if the value is falsy.
Parameters
- $value bool
- $callback callable
- $default callable|null
unlessEmpty ( callable $callback , callable $default ) : static|mixed
Apply the callback unless the collection is empty.
Parameters
- $callback callable
- $default callable|null
unlessNotEmpty ( callable $callback , callable $default ) : static|mixed
Apply the callback unless the collection is not empty.
Parameters
- $callback callable
- $default callable|null
where ( $key , $operator , $value ) : static
Filter items by the given key value pair.
Parameters
- $key string
- $operator mixed
- $value mixed
whereNull ( $key ) : static
Filter items where the value for the given key is null.
Parameters
- $key string|null
whereNotNull ( $key ) : static
Filter items where the value for the given key is not null.
Parameters
- $key string|null
whereStrict ( $key , $value ) : static
Filter items by the given key value pair using strict comparison.
Parameters
- $key string
- $value mixed
whereIn ( $key , $values , $strict ) : static
Filter items by the given key value pair.
Parameters
- $key string
- $values mixed
- $strict bool
whereInStrict ( $key , $values ) : static
Filter items by the given key value pair using strict comparison.
Parameters
- $key string
- $values mixed
whereBetween ( $key , $values ) : static
Filter items such that the value of the given key is between the given values.
Parameters
- $key string
- $values array
whereNotBetween ( $key , $values ) : static
Filter items such that the value of the given key is not between the given values.
Parameters
- $key string
- $values array
whereNotIn ( $key , $values , $strict ) : static
Filter items by the given key value pair.
Parameters
- $key string
- $values mixed
- $strict bool
whereNotInStrict ( $key , $values ) : static
Filter items by the given key value pair using strict comparison.
Parameters
- $key string
- $values mixed
whereInstanceOf ( $type ) : static
Filter the items, removing any items that don't match the given type(s).
Parameters
- $type string|string[]
first ( callable $callback , $default ) : mixed
Get the first item from the enumerable passing the given truth test.
Parameters
- $callback callable|null
- $default mixed
firstWhere ( $key , $operator , $value ) : mixed
Get the first item by the given key value pair.
Parameters
- $key string
- $operator mixed
- $value mixed
flatten ( $depth ) : static
Get a flattened array of the items in the collection.
Parameters
- $depth int
flip ( ) : static
Flip the values with their keys.
get ( $key , $default ) : mixed
Get an item from the collection by key.
Parameters
- $key mixed
- $default mixed
groupBy ( $groupBy , $preserveKeys ) : static
Group an associative array by a field or using a callback.
Parameters
- $groupBy array|callable|string
- $preserveKeys bool
keyBy ( $keyBy ) : static
Key an associative array by a field or using a callback.
Parameters
- $keyBy callable|string
has ( $key ) : bool
Determine if an item exists in the collection by key.
Parameters
- $key mixed
implode ( $value , $glue ) : string
Concatenate values of a given key as a string.
Parameters
- $value string
- $glue string|null
intersect ( $items ) : static
Intersect the collection with the given items.
Parameters
- $items mixed
intersectByKeys ( $items ) : static
Intersect the collection with the given items by key.
Parameters
- $items mixed
isEmpty ( ) : bool
Determine if the collection is empty or not.
isNotEmpty ( ) : bool
Determine if the collection is not empty.
join ( $glue , $finalGlue ) : string
Join all items from the collection using a string. The final items can use a separate glue string.
Parameters
- $glue string
- $finalGlue string
keys ( ) : static
Get the keys of the collection items.
last ( callable $callback , $default ) : mixed
Get the last item from the collection.
Parameters
- $callback callable|null
- $default mixed
map ( callable $callback ) : static
Run a map over each of the items.
Parameters
- $callback callable
mapSpread ( callable $callback ) : static
Run a map over each nested chunk of items.
Parameters
- $callback callable
mapToDictionary ( callable $callback ) : static
Run a dictionary map over the items.
Parameters
- $callback callable
mapToGroups ( callable $callback ) : static
Run a grouping map over the items.
Parameters
- $callback callable
mapWithKeys ( callable $callback ) : static
Run an associative map over each of the items.
Parameters
- $callback callable
flatMap ( callable $callback ) : static
Map a collection and flatten the result by a single level.
Parameters
- $callback callable
mapInto ( $class ) : static
Map the values into a new class.
Parameters
- $class string
merge ( $items ) : static
Merge the collection with the given items.
Parameters
- $items mixed
mergeRecursive ( $items ) : static
Recursively merge the collection with the given items.
Parameters
- $items mixed
combine ( $values ) : static
Create a collection by using this collection for keys and another for its values.
Parameters
- $values mixed
union ( $items ) : static
Union the collection with the given items.
Parameters
- $items mixed
min ( $callback ) : mixed
Get the min value of a given key.
Parameters
- $callback callable|string|null
max ( $callback ) : mixed
Get the max value of a given key.
Parameters
- $callback callable|string|null
nth ( $step , $offset ) : static
Create a new collection consisting of every n-th element.
Parameters
- $step int
- $offset int
only ( $keys ) : static
Get the items with the specified keys.
Parameters
- $keys mixed
forPage ( $page , $perPage ) : static
"Paginate" the collection by slicing it into a smaller collection.
Parameters
- $page int
- $perPage int
partition ( $key , $operator , $value ) : static
Partition the collection into two arrays using the given callback or key.
Parameters
- $key callable|string
- $operator mixed
- $value mixed
concat ( $source ) : static
Push all of the given items onto the collection.
Parameters
- $source iterable
random ( $number ) : static|mixed
Get one or a specified number of items randomly from the collection.
Parameters
- $number int|null
reduce ( callable $callback , $initial ) : mixed
Reduce the collection to a single value.
Parameters
- $callback callable
- $initial mixed
replace ( $items ) : static
Replace the collection items with the given items.
Parameters
- $items mixed
replaceRecursive ( $items ) : static
Recursively replace the collection items with the given items.
Parameters
- $items mixed
reverse ( ) : static
Reverse items order.
search ( $value , $strict ) : mixed
Search the collection for a given value and return the corresponding key if successful.
Parameters
- $value mixed
- $strict bool
shuffle ( $seed ) : static
Shuffle the items in the collection.
Parameters
- $seed int|null
skip ( $count ) : static
Skip the first {$count} items.
Parameters
- $count int
skipUntil ( $value ) : static
Skip items in the collection until the given condition is met.
Parameters
- $value mixed
skipWhile ( $value ) : static
Skip items in the collection while the given condition is met.
Parameters
- $value mixed
slice ( $offset , $length ) : static
Get a slice of items from the enumerable.
Parameters
- $offset int
- $length int|null
split ( $numberOfGroups ) : static
Split a collection into a certain number of groups.
Parameters
- $numberOfGroups int
chunk ( $size ) : static
Chunk the collection into chunks of the given size.
Parameters
- $size int
chunkWhile ( callable $callback ) : static
Chunk the collection into chunks with a callback.
Parameters
- $callback callable
sort ( $callback ) : static
Sort through each item with a callback.
Parameters
- $callback callable|null|int
sortDesc ( $options ) : static
Sort items in descending order.
Parameters
- $options int
sortBy ( $callback , $options , $descending ) : static
Sort the collection using the given callback.
Parameters
- $callback callable|string
- $options int
- $descending bool
sortByDesc ( $callback , $options ) : static
Sort the collection in descending order using the given callback.
Parameters
- $callback callable|string
- $options int
sortKeys ( $options , $descending ) : static
Sort the collection keys.
Parameters
- $options int
- $descending bool
sortKeysDesc ( $options ) : static
Sort the collection keys in descending order.
Parameters
- $options int
sum ( $callback ) : mixed
Get the sum of the given values.
Parameters
- $callback callable|string|null
take ( $limit ) : static
Take the first or last {$limit} items.
Parameters
- $limit int
takeUntil ( $value ) : static
Take items in the collection until the given condition is met.
Parameters
- $value mixed
takeWhile ( $value ) : static
Take items in the collection while the given condition is met.
Parameters
- $value mixed
tap ( callable $callback ) : $this
Pass the collection to the given callback and then return it.
Parameters
- $callback callable
pipe ( callable $callback ) : mixed
Pass the enumerable to the given callback and return the result.
Parameters
- $callback callable
pluck ( $value , $key ) : static
Get the values of a given key.
Parameters
- $value string|array
- $key string|null
reject ( $callback ) : static
Create a collection of all elements that do not pass a given truth test.
Parameters
- $callback callable|mixed
unique ( $key , $strict ) : static
Return only unique items from the collection array.
Parameters
- $key string|callable|null
- $strict bool
uniqueStrict ( $key ) : static
Return only unique items from the collection array using strict comparison.
Parameters
- $key string|callable|null
values ( ) : static
Reset the keys on the underlying array.
pad ( $size , $value ) : static
Pad collection to the specified length with a value.
Parameters
- $size int
- $value mixed
countBy ( $callback ) : static
Count the number of items in the collection using a given truth test.
Parameters
- $callback callable|null
zip ( $items ) : static
Zip the collection together with one or more arrays.
Parameters
- $items mixed
__toString ( ) : string
Convert the collection to its string representation.
proxy ( $method ) : void
Add a method to the list of proxied methods.
Parameters
- $method string
__get ( $key ) : mixed
Dynamically access collection proxies.
Parameters
- $key string