Collection
class Collection implements ArrayAccess, Arrayable, Countable, IteratorAggregate, Jsonable, JsonSerializable (View source)
Traits
Methods
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Create a new collection.
Create a new collection instance if the value isn't one already.
Get all of the items in the collection.
Get the average value of a given key.
Alias for the "avg" method.
Collapse the collection of items into a single array.
Determine if an item exists in the collection.
Get the items in the collection that are not present in the given items.
Get the items in the collection whose keys are not present in the given items.
Execute a callback over each item.
Create a new collection consisting of every n-th element.
Get all items except for those with the specified keys.
Run a filter over each of the items.
Filter items by the given key value pair.
Filter items by the given key value pair using loose comparison.
Filter items by the given key value pair.
Filter items by the given key value pair using loose comparison.
Get the first item from the collection.
Get a flattened array of the items in the collection.
Flip the items in the collection.
Remove an item from the collection by key.
Get an item from the collection by key.
Group an associative array by a field or using a callback.
Key an associative array by a field or using a callback.
Determine if an item exists in the collection by key.
Concatenate values of a given key as a string.
Intersect the collection with the given items.
Determine if the collection is empty or not.
Get the keys of the collection items.
Get the last item from the collection.
Get the values of a given key.
Alias for the "pluck" method.
Run a map over each of the items.
Map a collection and flatten the result by a single level.
Get the max value of a given key.
Merge the collection with the given items.
Create a collection by using this collection for keys and another for its values.
Union the collection with the given items.
Get the min value of a given key.
Get the items with the specified keys.
"Paginate" the collection by slicing it into a smaller collection.
Get and remove the last item from the collection.
Push an item onto the beginning of the collection.
Push an item onto the end of the collection.
Get and remove an item from the collection.
Put an item in the collection by key.
Get one or more items randomly from the collection.
Reduce the collection to a single value.
Create a collection of all elements that do not pass a given truth test.
Reverse items order.
Search the collection for a given value and return the corresponding key if successful.
Get and remove the first item from the collection.
Shuffle the items in the collection.
Slice the underlying collection array.
Chunk the underlying collection array.
Sort through each item with a callback.
Sort the collection using the given callback.
Sort the collection in descending order using the given callback.
Splice a portion of the underlying collection array.
Get the sum of the given values.
Take the first or last {$limit} items.
Transform each item in the collection using a callback.
Return only unique items from the collection array.
Reset the keys on the underlying array.
Zip the collection together with one or more arrays.
Get the collection of items as a plain array.
Convert the object into something JSON serializable.
Get the collection of items as JSON.
Get an iterator for the items.
Get a CachingIterator instance.
Count the number of items in the collection.
Determine if an item exists at an offset.
Get an item at a given offset.
Set the item at a given offset.
Unset the item at a given offset.
Convert the collection to its string representation.
Details
static
mixed
__callStatic(
string $method,
array $parameters)
Dynamically handle calls to the class.
at line line 44
static
Collection
make(
mixed $items = array())
Create a new collection instance if the value isn't one already.
at line line 100
bool
contains(
mixed $key,
mixed $value = null)
Determine if an item exists in the collection.
at line line 121
Collection
diff(
mixed $items)
Get the items in the collection that are not present in the given items.
at line line 132
Collection
diffKeys(
mixed $items)
Get the items in the collection whose keys are not present in the given items.
at line line 161
Collection
every(
int $step,
int $offset)
Create a new collection consisting of every n-th element.
at line line 184
Collection
except(
mixed $keys)
Get all items except for those with the specified keys.
at line line 222
Collection
where(
string $key,
mixed $value,
bool $strict = true)
Filter items by the given key value pair.
at line line 237
Collection
whereLoose(
string $key,
mixed $value)
Filter items by the given key value pair using loose comparison.
at line line 250
Collection
whereIn(
string $key,
array $values,
bool $strict = true)
Filter items by the given key value pair.
at line line 264
Collection
whereInLoose(
string $key,
array $values)
Filter items by the given key value pair using loose comparison.
at line line 276
mixed
first(
callable $callback = null,
mixed $default = null)
Get the first item from the collection.
at line line 287
Collection
flatten(
int $depth = INF)
Get a flattened array of the items in the collection.
at line line 324
mixed
get(
mixed $key,
mixed $default = null)
Get an item from the collection by key.
at line line 340
Collection
groupBy(
callable|string $groupBy,
bool $preserveKeys = false)
Group an associative array by a field or using a callback.
at line line 371
Collection
keyBy(
callable|string $keyBy)
Key an associative array by a field or using a callback.
at line line 402
string
implode(
string $value,
string $glue = null)
Concatenate values of a given key as a string.
at line line 462
mixed
last(
callable $callback = null,
mixed $default = null)
Get the last item from the collection.
at line line 474
Collection
pluck(
string $value,
string|null $key = null)
Get the values of a given key.
at line line 488
Collection
lists(
string $value,
string|null $key = null)
Alias for the "pluck" method.
at line line 514
Collection
flatMap(
callable $callback)
Map a collection and flatten the result by a single level.
at line line 551
Collection
combine(
mixed $values)
Create a collection by using this collection for keys and another for its values.
at line line 602
Collection
forPage(
int $page,
int $perPage)
"Paginate" the collection by slicing it into a smaller collection.
at line line 624
$this
prepend(
mixed $value,
mixed $key = null)
Push an item onto the beginning of the collection.
at line line 651
mixed
pull(
mixed $key,
mixed $default = null)
Get and remove an item from the collection.
at line line 700
mixed
reduce(
callable $callback,
mixed $initial = null)
Reduce the collection to a single value.
at line line 711
Collection
reject(
callable|mixed $callback)
Create a collection of all elements that do not pass a given truth test.
at line line 741
mixed
search(
mixed $value,
bool $strict = false)
Search the collection for a given value and return the corresponding key if successful.
at line line 787
Collection
slice(
int $offset,
int $length = null)
Slice the underlying collection array.
at line line 815
Collection
sort(
callable $callback = null)
Sort through each item with a callback.
at line line 839
Collection
sortBy(
callable|string $callback,
int $options = SORT_REGULAR,
bool $descending = false)
Sort the collection using the given callback.
at line line 872
Collection
sortByDesc(
callable|string $callback,
int $options = SORT_REGULAR)
Sort the collection in descending order using the given callback.
at line line 885
Collection
splice(
int $offset,
int|null $length = null,
mixed $replacement = array())
Splice a portion of the underlying collection array.
at line line 934
$this
transform(
callable $callback)
Transform each item in the collection using a callback.
at line line 947
Collection
unique(
string|callable|null $key = null)
Return only unique items from the collection array.
at line line 1002
Collection
zip(
mixed $items)
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]]
at line line 1074
CachingIterator
getCachingIterator(
int $flags = CachingIterator::CALL_TOSTRING)
Get a CachingIterator instance.