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 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.
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.
Alias for the "pluck" method.
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.
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 $value,
bool $strict = true)
Filter items by the given key value pair.
in Collection at line line 237
Collection
whereLoose(
string $key,
mixed $value)
Filter items by the given key value pair using loose comparison.
in Collection at line line 250
Collection
whereIn(
string $key,
array $values,
bool $strict = true)
Filter items by the given key value pair.
in Collection at line line 264
Collection
whereInLoose(
string $key,
array $values)
Filter items by the given key value pair using loose comparison.
in Collection at line line 276
mixed
first(
callable $callback = null,
mixed $default = null)
Get the first item from the collection.
at line line 310
Collection
flatten(
int $depth = INF)
Get a flattened array of the items in the collection.
in Collection at line line 308
$this
forget(
string|array $keys)
Remove an item from the collection by key.
in Collection at line line 324
mixed
get(
mixed $key,
mixed $default = null)
Get an item from the collection by key.
in Collection at line line 340
Collection
groupBy(
callable|string $groupBy,
bool $preserveKeys = false)
Group an associative array by a field or using a callback.
in Collection at line line 371
Collection
keyBy(
callable|string $keyBy)
Key an associative array by a field or using a callback.
in Collection at line line 390
bool
has(
mixed $key)
Determine if an item exists in the collection by key.
in Collection at line line 402
string
implode(
string $value,
string $glue = null)
Concatenate values of a given key as a string.
in Collection at line line 462
mixed
last(
callable $callback = null,
mixed $default = null)
Get the last item from the collection.
at line line 268
Collection
pluck(
string $value,
string|null $key = null)
Get an array with the values of a given key.
in Collection at line line 488
Collection
lists(
string $value,
string|null $key = null)
Alias for the "pluck" method.
in Collection at line line 499
Collection
map(
callable $callback)
Run a map over each of the items.
in Collection at line line 514
Collection
flatMap(
callable $callback)
Map a collection and flatten the result by a single level.
in Collection at line line 525
mixed
max(
string|null $key = null)
Get the max value of a given key.
in Collection at line line 551
Collection
combine(
mixed $values)
Create a collection by using this collection for keys and another for its values.
in Collection at line line 573
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 602
Collection
forPage(
int $page,
int $perPage)
"Paginate" the collection by slicing it into a smaller collection.
in Collection at line line 624
$this
prepend(
mixed $value,
mixed $key = null)
Push an item onto the beginning of the collection.
in Collection at line line 637
$this
push(
mixed $value)
Push an item onto the end of the collection.
in Collection at line line 651
mixed
pull(
mixed $key,
mixed $default = null)
Get and remove an item from the collection.
in Collection at line line 663
$this
put(
mixed $key,
mixed $value)
Put an item in the collection by key.
in Collection at line line 678
mixed
random(
int $amount = 1)
Get one or more items randomly from the collection.
in Collection at line line 700
mixed
reduce(
callable $callback,
mixed $initial = null)
Reduce the collection to a single value.
in Collection at line line 711
Collection
reject(
callable|mixed $callback)
Create a collection of all elements that do not pass a given truth test.
in Collection 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.
in Collection at line line 787
Collection
slice(
int $offset,
int $length = null)
Slice the underlying collection array.
in Collection at line line 815
Collection
sort(
callable $callback = null)
Sort through each item with a callback.
in Collection at line line 839
Collection
sortBy(
callable|string $callback,
int $options = SORT_REGULAR,
bool $descending = false)
Sort the collection using the given callback.
in Collection at line line 872
Collection
sortByDesc(
callable|string $callback,
int $options = SORT_REGULAR)
Sort the collection in descending order using the given callback.
in Collection at line line 885
Collection
splice(
int $offset,
int|null $length = null,
mixed $replacement = array())
Splice a portion of the underlying collection array.
in Collection at line line 900
mixed
sum(
callable|string|null $callback = null)
Get the sum of the given values.
in Collection at line line 934
$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 1032
array
jsonSerialize()
Convert the object into something JSON serializable.
in Collection at line line 1074
CachingIterator
getCachingIterator(
int $flags = CachingIterator::CALL_TOSTRING)
Get a CachingIterator instance.
in Collection at line line 1095
bool
offsetExists(
mixed $key)
Determine if an item exists at an offset.
in Collection at line line 1118
void
offsetSet(
mixed $key,
mixed $value)
Set the item at a given offset.
in Collection at line line 1143
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 233
$this
withHidden(
array|string $attributes)
Make the given, typically hidden, attributes visible across the entire collection.
at line line 244
array
getDictionary(
ArrayAccess|array|null $items = null)
Get a dictionary keyed by primary keys.