Collection
Implements
Uses
Properties
$items array
The items contained in the collection.
Methods
__construct ( $items ) : void
Create a new collection.
Parameters
- $items mixed
range ( $from , $to ) : static
Create a collection with the given range.
Parameters
- $from int
- $to int
all ( ) : array
Get all of the items in the collection.
avg ( $callback ) : mixed
Get the average value of a given key.
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 collection of items into a single array.
contains ( $key , $operator , $value ) : bool
Determine if an item exists in the collection.
Parameters
- $key mixed
- $operator mixed
- $value mixed
doesntContain ( $key , $operator , $value ) : bool
Determine if an item is not contained in the collection.
Parameters
- $key mixed
- $operator mixed
- $value mixed
crossJoin ( $lists ) : static
Cross join with the given lists, returning all possible permutations.
Parameters
- $lists mixed
diff ( $items ) : static
Get the items in the collection that are not present in the given items.
Parameters
- $items mixed
diffUsing ( $items , callable $callback ) : static
Get the items in the collection that are not present in the given items, using the callback.
Parameters
- $items mixed
- $callback callable
diffAssoc ( $items ) : static
Get the items in the collection whose keys and values are not present in the given items.
Parameters
- $items mixed
diffAssocUsing ( $items , callable $callback ) : static
Get the items in the collection 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 in the collection whose keys are not present in the given items.
Parameters
- $items mixed
diffKeysUsing ( $items , callable $callback ) : static
Get the items in the collection whose keys are not present in the given items, using the callback.
Parameters
- $items mixed
- $callback callable
duplicates ( $callback , $strict ) : static
Retrieve duplicate items from the collection.
Parameters
- $callback callable|string|null
- $strict bool
duplicatesStrict ( $callback ) : static
Retrieve duplicate items from the collection using strict comparison.
Parameters
- $callback callable|string|null
duplicateComparator ( $strict ) : Closure
Get the comparison function to detect duplicates.
Parameters
- $strict bool
except ( $keys ) : static
Get all items except for those with the specified keys.
Parameters
- $keys Collection |mixed
filter ( callable $callback ) : static
Run a filter over each of the items.
Parameters
- $callback callable|null
first ( callable $callback , $default ) : mixed
Get the first item from the collection passing the given truth test.
Parameters
- $callback callable|null
- $default mixed
flatten ( $depth ) : static
Get a flattened array of the items in the collection.
Parameters
- $depth int
flip ( ) : static
Flip the items in the collection.
forget ( $keys ) : $this
Remove an item from the collection by key.
Parameters
- $keys string|int|array
get ( $key , $default ) : mixed
Get an item from the collection by key.
Parameters
- $key mixed
- $default mixed
getOrPut ( $key , $value ) : mixed
Get an item from the collection by key or add it to collection if it does not exist.
Parameters
- $key mixed
- $value 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
hasAny ( $key ) : bool
Determine if any of the keys exist in the collection.
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.
containsOneItem ( ) : bool
Determine if the collection contains a single item.
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
pluck ( $value , $key ) : static
Get the values of a given key.
Parameters
- $value string|array|int|null
- $key string|null
map ( callable $callback ) : static
Run a map over each of the items.
Parameters
- $callback callable
mapToDictionary ( callable $callback ) : static
Run a dictionary map over the items.
Parameters
- $callback callable
mapWithKeys ( callable $callback ) : static
Run an associative map over each of the items.
Parameters
- $callback callable
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
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
pop ( $count ) : mixed
Get and remove the last N items from the collection.
Parameters
- $count int
prepend ( $value , $key ) : $this
Push an item onto the beginning of the collection.
Parameters
- $value mixed
- $key mixed
push ( $values ) : $this
Push one or more items onto the end of the collection.
Parameters
- $values mixed
concat ( $source ) : static
Push all of the given items onto the collection.
Parameters
- $source iterable
pull ( $key , $default ) : mixed
Get and remove an item from the collection.
Parameters
- $key mixed
- $default mixed
put ( $key , $value ) : $this
Put an item in the collection by key.
Parameters
- $key mixed
- $value mixed
random ( $number ) : static|mixed
Get one or a specified number of items randomly from the collection.
Parameters
- $number int|null
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
shift ( $count ) : mixed
Get and remove the first N items from the collection.
Parameters
- $count int
shuffle ( $seed ) : static
Shuffle the items in the collection.
Parameters
- $seed int|null
sliding ( $size , $step ) : static
Create chunks representing a "sliding window" view of the items in the collection.
Parameters
- $size int
- $step int
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
Slice the underlying collection array.
Parameters
- $offset int
- $length int|null
split ( $numberOfGroups ) : static
Split a collection into a certain number of groups.
Parameters
- $numberOfGroups int
splitIn ( $numberOfGroups ) : static
Split a collection into a certain number of groups, and fill the first groups completely.
Parameters
- $numberOfGroups int
sole ( $key , $operator , $value ) : mixed
Get the first item in the collection, but only if exactly one item exists. Otherwise, throw an exception.
Parameters
- $key mixed
- $operator mixed
- $value mixed
firstOrFail ( $key , $operator , $value ) : mixed
Get the first item in the collection but throw an exception if no matching items exist.
Parameters
- $key mixed
- $operator mixed
- $value mixed
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|int|null
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|array|string
- $options int
- $descending bool
sortByMany ( array $comparisons ) : static
Sort the collection using multiple comparisons.
Parameters
- $comparisons array
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
sortKeysUsing ( callable $callback ) : static
Sort the collection keys using a callback.
Parameters
- $callback callable
splice ( $offset , $length , $replacement ) : static
Splice a portion of the underlying collection array.
Parameters
- $offset int
- $length int|null
- $replacement mixed
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
transform ( callable $callback ) : $this
Transform each item in the collection using a callback.
Parameters
- $callback callable
undot ( ) : static
Convert a flatten "dot" notation array into an expanded array.
unique ( $key , $strict ) : static
Return only unique items from the collection array.
Parameters
- $key string|callable|null
- $strict bool
values ( ) : static
Reset the keys on the underlying array.
zip ( $items ) : static
Zip the collection together with one or more arrays.
Parameters
- $items mixed
pad ( $size , $value ) : static
Pad collection to the specified length with a value.
Parameters
- $size int
- $value mixed
count ( ) : int
Count the number of items in the collection.
countBy ( $countBy ) : static
Count the number of items in the collection by a field or using a callback.
Parameters
- $countBy callable|string
add ( $item ) : $this
Add an item to the collection.
Parameters
- $item mixed
offsetExists ( $key ) : bool
Determine if an item exists at an offset.
Parameters
- $key mixed
offsetGet ( $key ) : mixed
Get an item at a given offset.
Parameters
- $key mixed
offsetSet ( $key , $value ) : void
Set the item at a given offset.
Parameters
- $key mixed
- $value mixed
offsetUnset ( $key ) : void
Unset the item at a given offset.
Parameters
- $key mixed