Collection
class Collection extends Collection (View source)
Traits
Methods
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Create a new collection instance if the value isn't one already.
Collapse the collection of items into a single array.
Determine if a key exists in the collection.
Diff the collection with the given items.
Get the items in the collection whose keys are not present in the given items.
Create a new collection consisting of every n-th element.
Returns all models in the collection except the models with specified keys.
Filter items by the given key value pair.
Filter items by the given key value pair.
Filter items by the given key value pair using strict comparison.
Get the first item from the collection.
Get a flattened array of the items in the collection.
Flip the items in the collection.
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.
Concatenate values of a given key as a string.
Intersect the collection with the given items.
Get the keys of the collection items.
Get the last item from the collection.
Get an array with the values of a given key.
Map a collection and flatten the result by a single level.
Merge the collection with the given items.
Create a collection by using this collection for keys and another for its values.
Returns only the models from the collection with the specified keys.
"Paginate" the collection by slicing it into a smaller collection.
Push an item onto the beginning of the collection.
Get and remove an item from the collection.
Reduce the collection to a single value.
Create a collection of all elements that do not pass a given truth test.
Search the collection for a given value and return the corresponding key if successful.
Slice the underlying collection array.
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.
Transform each item in the collection using a callback.
Return only unique items from the collection.
Zip the collection together with one or more arrays.
Get a CachingIterator instance.
Load a set of relationships onto the collection.
Add an item to the collection.
Get the array of primary keys.
Make the given, typically visible, attributes hidden across the entire collection.
Make the given, typically hidden, attributes visible across the entire collection.
Get a base Support collection instance from this collection.
Details
static
mixed
__callStatic(
string $method,
array $parameters)
Dynamically handle calls to the class.
in Collection at line line 44
static
Collection
make(
mixed $items = array())
Create a new collection instance if the value isn't one already.
in Collection at line line 65
mixed
avg(
string|null $key = null)
Get the average value of a given key.
at line line 70
bool
contains(
mixed $key,
mixed $value = null)
Determine if a key exists in the collection.
in Collection at line line 132
Collection
diffKeys(
mixed $items)
Get the items in the collection whose keys are not present in the given items.
in Collection at line line 161
Collection
every(
int $step,
int $offset)
Create a new collection consisting of every n-th element.
at line line 192
Collection
except(
mixed $keys)
Returns all models in the collection except the models with specified keys.
in Collection at line line 197
Collection
filter(
callable $callback = null)
Run a filter over each of the items.
in Collection at line line 222
Collection
where(
string $key,
mixed $operator,
mixed $value = null)
Filter items by the given key value pair.
in Collection at line line 270
Collection
whereIn(
string $key,
array $values,
bool $strict = false)
Filter items by the given key value pair.
in Collection at line line 284
Collection
whereInStrict(
string $key,
array $values)
Filter items by the given key value pair using strict comparison.
in Collection at line line 296
mixed
first(
callable $callback = null,
mixed $default = null)
Get the first item from the collection.
at line line 297
Collection
flatten(
int $depth = INF)
Get a flattened array of the items in the collection.
in Collection at line line 328
$this
forget(
string|array $keys)
Remove an item from the collection by key.
in Collection at line line 344
mixed
get(
mixed $key,
mixed $default = null)
Get an item from the collection by key.
in Collection at line line 360
Collection
groupBy(
callable|string $groupBy,
bool $preserveKeys = false)
Group an associative array by a field or using a callback.
in Collection at line line 391
Collection
keyBy(
callable|string $keyBy)
Key an associative array by a field or using a callback.
in Collection at line line 410
bool
has(
mixed $key)
Determine if an item exists in the collection by key.
in Collection at line line 422
string
implode(
string $value,
string $glue = null)
Concatenate values of a given key as a string.
in Collection at line line 482
mixed
last(
callable $callback = null,
mixed $default = null)
Get the last item from the collection.
at line line 255
Collection
pluck(
string $value,
string|null $key = null)
Get an array with the values of a given key.
in Collection at line line 505
Collection
map(
callable $callback)
Run a map over each of the items.
in Collection at line line 520
Collection
flatMap(
callable $callback)
Map a collection and flatten the result by a single level.
in Collection at line line 531
mixed
max(
string|null $key = null)
Get the max value of a given key.
in Collection at line line 557
Collection
combine(
mixed $values)
Create a collection by using this collection for keys and another for its values.
in Collection at line line 579
mixed
min(
string|null $key = null)
Get the min value of a given key.
at line line 179
Collection
only(
mixed $keys)
Returns only the models from the collection with the specified keys.
in Collection at line line 608
Collection
forPage(
int $page,
int $perPage)
"Paginate" the collection by slicing it into a smaller collection.
in Collection at line line 630
$this
prepend(
mixed $value,
mixed $key = null)
Push an item onto the beginning of the collection.
in Collection at line line 643
$this
push(
mixed $value)
Push an item onto the end of the collection.
in Collection at line line 657
mixed
pull(
mixed $key,
mixed $default = null)
Get and remove an item from the collection.
in Collection at line line 669
$this
put(
mixed $key,
mixed $value)
Put an item in the collection by key.
in Collection at line line 684
mixed
random(
int $amount = 1)
Get one or more items randomly from the collection.
in Collection at line line 706
mixed
reduce(
callable $callback,
mixed $initial = null)
Reduce the collection to a single value.
in Collection at line line 717
Collection
reject(
callable|mixed $callback)
Create a collection of all elements that do not pass a given truth test.
in Collection at line line 747
mixed
search(
mixed $value,
bool $strict = false)
Search the collection for a given value and return the corresponding key if successful.
in Collection at line line 793
Collection
slice(
int $offset,
int $length = null)
Slice the underlying collection array.
in Collection at line line 821
Collection
sort(
callable $callback = null)
Sort through each item with a callback.
in Collection at line line 845
Collection
sortBy(
callable|string $callback,
int $options = SORT_REGULAR,
bool $descending = false)
Sort the collection using the given callback.
in Collection at line line 878
Collection
sortByDesc(
callable|string $callback,
int $options = SORT_REGULAR)
Sort the collection in descending order using the given callback.
in Collection at line line 891
Collection
splice(
int $offset,
int|null $length = null,
mixed $replacement = array())
Splice a portion of the underlying collection array.
in Collection at line line 906
mixed
sum(
callable|string|null $callback = null)
Get the sum of the given values.
in Collection at line line 940
$this
transform(
callable $callback)
Transform each item in the collection using a callback.
at line line 164
Collection
unique(
string|callable|null $key = null)
Return only unique items from the collection.
in Collection at line line 1038
array
jsonSerialize()
Convert the object into something JSON serializable.
in Collection at line line 1080
CachingIterator
getCachingIterator(
int $flags = CachingIterator::CALL_TOSTRING)
Get a CachingIterator instance.
in Collection at line line 1101
bool
offsetExists(
mixed $key)
Determine if an item exists at an offset.
in Collection at line line 1124
void
offsetSet(
mixed $key,
mixed $value)
Set the item at a given offset.
in Collection at line line 1149
string
__toString()
Convert the collection to its string representation.
at line line 17
Model
find(
mixed $key,
mixed $default = null)
Find a model in the collection by key.
at line line 205
$this
makeHidden(
array|string $attributes)
Make the given, typically visible, attributes hidden across the entire collection.
at line line 218
$this
makeVisible(
array|string $attributes)
Make the given, typically hidden, attributes visible across the entire collection.
at line line 231
array
getDictionary(
ArrayAccess|array|null $items = null)
Get a dictionary keyed by primary keys.