class Collection extends Collection (View source)

Methods

void
__construct(mixed $items = array())

Create a new collection.

static Collection
make(mixed $items = null)

Create a new collection instance if the value isn't one already.

array
all()

Get all of the items in the collection.

collapse()

Collapse the collection of items into a single array.

bool
contains(mixed $key, mixed $value = null)

Determine if a key exists in the collection.

diff(Collection|Arrayable|array $items)

Diff the collection with the given items.

$this
each(callable $callback)

Execute a callback over each item.

fetch(string $key)

Fetch a nested element of the collection.

filter(callable $callback)

Run a filter over each of the items.

where(string $key, mixed $value, bool $strict = true)

Filter items by the given key value pair.

whereLoose(string $key, mixed $value)

Filter items by the given key value pair using loose comparison.

mixed|null
first(callable $callback = null, mixed $default = null)

Get the first item from the collection.

flatten()

Get a flattened array of the items in the collection.

flip()

Flip the items in the collection.

void
forget(mixed $key)

Remove an item from the collection by key.

mixed
get(mixed $key, mixed $default = null)

Get an item from the collection by key.

groupBy(callable|string $groupBy)

Group an associative array by a field or using a callback.

keyBy(callable|string $keyBy)

Key an associative array by a field or using a callback.

bool
has(mixed $key)

Determine if an item exists in the collection by key.

string
implode(string $value, string $glue = null)

Concatenate values of a given key as a string.

intersect(Collection|Arrayable|array $items)

Intersect the collection with the given items.

bool
isEmpty()

Determine if the collection is empty or not.

keys()

Get the keys of the collection items.

mixed|null
last()

Get the last item from the collection.

array
lists(string $value, string $key = null)

Get an array with the values of a given key.

map(callable $callback)

Run a map over each of the items.

merge(Collection|Arrayable|array $items)

Merge the collection with the given items.

forPage(int $page, int $perPage)

"Paginate" the collection by slicing it into a smaller collection.

mixed|null
pop()

Get and remove the last item from the collection.

void
prepend(mixed $value)

Push an item onto the beginning of the collection.

void
push(mixed $value)

Push an item onto the end of the collection.

mixed
pull(mixed $key, mixed $default = null)

Pulls an item from the collection.

void
put(mixed $key, mixed $value)

Put an item in the collection by key.

mixed
random(int $amount = 1)

Get one or more items randomly from the collection.

mixed
reduce(callable $callback, mixed $initial = null)

Reduce the collection to a single value.

reject(callable|mixed $callback)

Create a collection of all elements that do not pass a given truth test.

reverse()

Reverse items order.

mixed
search(mixed $value, bool $strict = false)

Search the collection for a given value and return the corresponding key if successful.

mixed|null
shift()

Get and remove the first item from the collection.

$this
shuffle()

Shuffle the items in the collection.

slice(int $offset, int $length = null, bool $preserveKeys = false)

Slice the underlying collection array.

chunk(int $size, bool $preserveKeys = false)

Chunk the underlying collection array.

$this
sort(callable $callback)

Sort through each item with a callback.

$this
sortBy(callable|string $callback, int $options = SORT_REGULAR, bool $descending = false)

Sort the collection using the given callback.

$this
sortByDesc(callable|string $callback, int $options = SORT_REGULAR)

Sort the collection in descending order using the given callback.

splice(int $offset, int $length, mixed $replacement = array())

Splice portion of the underlying collection array.

mixed
sum(callable|string|null $callback = null)

Get the sum of the given values.

take(int $limit = null)

Take the first or last {$limit} items.

$this
transform(callable $callback)

Transform each item in the collection using a callback.

unique()

Return only unique items from the collection.

values()

Reset the keys on the underlying array.

array
toArray()

Get the collection of items as a plain array.

array
jsonSerialize()

Convert the object into something JSON serializable.

string
toJson(int $options)

Get the collection of items as JSON.

getIterator()

Get an iterator for the items.

getCachingIterator(int $flags = CachingIterator::CALL_TOSTRING)

Get a CachingIterator instance.

int
count()

Count the number of items in the collection.

bool
offsetExists(mixed $key)

Determine if an item exists at an offset.

mixed
offsetGet(mixed $key)

Get an item at a given offset.

void
offsetSet(mixed $key, mixed $value)

Set the item at a given offset.

void
offsetUnset(string $key)

Unset the item at a given offset.

string
__toString()

Convert the collection to its string representation.

find(mixed $key, mixed $default = null)

Find a model in the collection by key.

$this
load(mixed $relations)

Load a set of relationships onto the collection.

$this
add(mixed $item)

Add an item to the collection.

mixed
max(string $key)

Get the max value of a given key.

mixed
min(string $key)

Get the min value of a given key.

array
modelKeys()

Get the array of primary keys.

only(mixed $keys)

Returns only the models from the collection with the specified keys.

except(mixed $keys)

Returns all models in the collection except the models with specified keys.

array
getDictionary(ArrayAccess|array $items = null)

Get a dictionary keyed by primary keys.

toBase()

Get a base Support collection instance from this collection.

Details

in Collection at line line 28
void __construct(mixed $items = array())

Create a new collection.

Parameters

mixed $items

Return Value

void

in Collection at line line 41
static Collection make(mixed $items = null)

Create a new collection instance if the value isn't one already.

Parameters

mixed $items

Return Value

Collection

in Collection at line line 51
array all()

Get all of the items in the collection.

Return Value

array

in Collection at line line 61
Collection collapse()

Collapse the collection of items into a single array.

Return Value

Collection

at line line 68
bool contains(mixed $key, mixed $value = null)

Determine if a key exists in the collection.

Parameters

mixed $key
mixed $value

Return Value

bool

at line line 155
Collection diff(Collection|Arrayable|array $items)

Diff the collection with the given items.

Parameters

Collection|Arrayable|array $items

Return Value

Collection

in Collection at line line 108
$this each(callable $callback)

Execute a callback over each item.

Parameters

callable $callback

Return Value

$this

at line line 88
Collection fetch(string $key)

Fetch a nested element of the collection.

Parameters

string $key

Return Value

Collection

in Collection at line line 132
Collection filter(callable $callback)

Run a filter over each of the items.

Parameters

callable $callback

Return Value

Collection

in Collection at line line 145
Collection where(string $key, mixed $value, bool $strict = true)

Filter items by the given key value pair.

Parameters

string $key
mixed $value
bool $strict

Return Value

Collection

in Collection at line line 161
Collection whereLoose(string $key, mixed $value)

Filter items by the given key value pair using loose comparison.

Parameters

string $key
mixed $value

Return Value

Collection

in Collection at line line 173
mixed|null first(callable $callback = null, mixed $default = null)

Get the first item from the collection.

Parameters

callable $callback
mixed $default

Return Value

mixed|null

in Collection at line line 188
Collection flatten()

Get a flattened array of the items in the collection.

Return Value

Collection

in Collection at line line 198
Collection flip()

Flip the items in the collection.

Return Value

Collection

in Collection at line line 209
void forget(mixed $key)

Remove an item from the collection by key.

Parameters

mixed $key

Return Value

void

in Collection at line line 221
mixed get(mixed $key, mixed $default = null)

Get an item from the collection by key.

Parameters

mixed $key
mixed $default

Return Value

mixed

in Collection at line line 237
Collection groupBy(callable|string $groupBy)

Group an associative array by a field or using a callback.

Parameters

callable|string $groupBy

Return Value

Collection

in Collection at line line 260
Collection keyBy(callable|string $keyBy)

Key an associative array by a field or using a callback.

Parameters

callable|string $keyBy

Return Value

Collection

in Collection at line line 283
bool has(mixed $key)

Determine if an item exists in the collection by key.

Parameters

mixed $key

Return Value

bool

in Collection at line line 295
string implode(string $value, string $glue = null)

Concatenate values of a given key as a string.

Parameters

string $value
string $glue

Return Value

string

at line line 178
Collection intersect(Collection|Arrayable|array $items)

Intersect the collection with the given items.

Parameters

Collection|Arrayable|array $items

Return Value

Collection

in Collection at line line 323
bool isEmpty()

Determine if the collection is empty or not.

Return Value

bool

in Collection at line line 344
Collection keys()

Get the keys of the collection items.

Return Value

Collection

in Collection at line line 354
mixed|null last()

Get the last item from the collection.

Return Value

mixed|null

in Collection at line line 366
array lists(string $value, string $key = null)

Get an array with the values of a given key.

Parameters

string $value
string $key

Return Value

array

in Collection at line line 377
Collection map(callable $callback)

Run a map over each of the items.

Parameters

callable $callback

Return Value

Collection

at line line 137
Collection merge(Collection|Arrayable|array $items)

Merge the collection with the given items.

Parameters

Collection|Arrayable|array $items

Return Value

Collection

in Collection at line line 400
Collection forPage(int $page, int $perPage)

"Paginate" the collection by slicing it into a smaller collection.

Parameters

int $page
int $perPage

Return Value

Collection

in Collection at line line 410
mixed|null pop()

Get and remove the last item from the collection.

Return Value

mixed|null

in Collection at line line 421
void prepend(mixed $value)

Push an item onto the beginning of the collection.

Parameters

mixed $value

Return Value

void

in Collection at line line 432
void push(mixed $value)

Push an item onto the end of the collection.

Parameters

mixed $value

Return Value

void

in Collection at line line 444
mixed pull(mixed $key, mixed $default = null)

Pulls an item from the collection.

Parameters

mixed $key
mixed $default

Return Value

mixed

in Collection at line line 456
void put(mixed $key, mixed $value)

Put an item in the collection by key.

Parameters

mixed $key
mixed $value

Return Value

void

in Collection at line line 467
mixed random(int $amount = 1)

Get one or more items randomly from the collection.

Parameters

int $amount

Return Value

mixed

in Collection at line line 483
mixed reduce(callable $callback, mixed $initial = null)

Reduce the collection to a single value.

Parameters

callable $callback
mixed $initial

Return Value

mixed

in Collection at line line 494
Collection reject(callable|mixed $callback)

Create a collection of all elements that do not pass a given truth test.

Parameters

callable|mixed $callback

Return Value

Collection

in Collection at line line 515
Collection reverse()

Reverse items order.

Return Value

Collection

Search the collection for a given value and return the corresponding key if successful.

Parameters

mixed $value
bool $strict

Return Value

mixed

in Collection at line line 547
mixed|null shift()

Get and remove the first item from the collection.

Return Value

mixed|null

in Collection at line line 557
$this shuffle()

Shuffle the items in the collection.

Return Value

$this

in Collection at line line 572
Collection slice(int $offset, int $length = null, bool $preserveKeys = false)

Slice the underlying collection array.

Parameters

int $offset
int $length
bool $preserveKeys

Return Value

Collection

in Collection at line line 584
Collection chunk(int $size, bool $preserveKeys = false)

Chunk the underlying collection array.

Parameters

int $size
bool $preserveKeys

Return Value

Collection

in Collection at line line 602
$this sort(callable $callback)

Sort through each item with a callback.

Parameters

callable $callback

Return Value

$this

in Collection at line line 617
$this sortBy(callable|string $callback, int $options = SORT_REGULAR, bool $descending = false)

Sort the collection using the given callback.

Parameters

callable|string $callback
int $options
bool $descending

Return Value

$this

in Collection at line line 657
$this sortByDesc(callable|string $callback, int $options = SORT_REGULAR)

Sort the collection in descending order using the given callback.

Parameters

callable|string $callback
int $options

Return Value

$this

in Collection at line line 670
Collection splice(int $offset, int $length, mixed $replacement = array())

Splice portion of the underlying collection array.

Parameters

int $offset
int $length
mixed $replacement

Return Value

Collection

in Collection at line line 681
mixed sum(callable|string|null $callback = null)

Get the sum of the given values.

Parameters

callable|string|null $callback

Return Value

mixed

in Collection at line line 705
Collection take(int $limit = null)

Take the first or last {$limit} items.

Parameters

int $limit

Return Value

Collection

in Collection at line line 718
$this transform(callable $callback)

Transform each item in the collection using a callback.

Parameters

callable $callback

Return Value

$this

at line line 200
Collection unique()

Return only unique items from the collection.

Return Value

Collection

in Collection at line line 740
Collection values()

Reset the keys on the underlying array.

Return Value

Collection

in Collection at line line 764
array toArray()

Get the collection of items as a plain array.

Return Value

array

in Collection at line line 778
array jsonSerialize()

Convert the object into something JSON serializable.

Return Value

array

in Collection at line line 789
string toJson(int $options)

Get the collection of items as JSON.

Parameters

int $options

Return Value

string

in Collection at line line 799
ArrayIterator getIterator()

Get an iterator for the items.

Return Value

ArrayIterator

in Collection at line line 810
CachingIterator getCachingIterator(int $flags = CachingIterator::CALL_TOSTRING)

Get a CachingIterator instance.

Parameters

int $flags

Return Value

CachingIterator

in Collection at line line 820
int count()

Count the number of items in the collection.

Return Value

int

in Collection at line line 831
bool offsetExists(mixed $key)

Determine if an item exists at an offset.

Parameters

mixed $key

Return Value

bool

in Collection at line line 842
mixed offsetGet(mixed $key)

Get an item at a given offset.

Parameters

mixed $key

Return Value

mixed

in Collection at line line 854
void offsetSet(mixed $key, mixed $value)

Set the item at a given offset.

Parameters

mixed $key
mixed $value

Return Value

void

in Collection at line line 872
void offsetUnset(string $key)

Unset the item at a given offset.

Parameters

string $key

Return Value

void

in Collection at line line 882
string __toString()

Convert the collection to its string representation.

Return Value

string

at line line 14
Model find(mixed $key, mixed $default = null)

Find a model in the collection by key.

Parameters

mixed $key
mixed $default

Return Value

Model

at line line 34
$this load(mixed $relations)

Load a set of relationships onto the collection.

Parameters

mixed $relations

Return Value

$this

at line line 54
$this add(mixed $item)

Add an item to the collection.

Parameters

mixed $item

Return Value

$this

at line line 99
mixed max(string $key)

Get the max value of a given key.

Parameters

string $key

Return Value

mixed

at line line 113
mixed min(string $key)

Get the min value of a given key.

Parameters

string $key

Return Value

mixed

at line line 126
array modelKeys()

Get the array of primary keys.

Return Value

array

at line line 213
Collection only(mixed $keys)

Returns only the models from the collection with the specified keys.

Parameters

mixed $keys

Return Value

Collection

at line line 226
Collection except(mixed $keys)

Returns all models in the collection except the models with specified keys.

Parameters

mixed $keys

Return Value

Collection

at line line 239
array getDictionary(ArrayAccess|array $items = null)

Get a dictionary keyed by primary keys.

Parameters

ArrayAccess|array $items

Return Value

array

at line line 258
Collection toBase()

Get a base Support collection instance from this collection.

Return Value

Collection