class Illuminate / Database / Eloquent / Collection
You are viewing an older version of the documentation. For the latest, please visit master documentation.

Collection

Extends

Implements

Methods

public

find ( $key , $default ) : Model |static|null

Find a model in the collection by key.

Parameters

  • $key mixed
  • $default mixed
public

load ( $relations ) : $this

Load a set of relationships onto the collection.

Parameters

  • $relations array|string
public

loadAggregate ( $relations , $column , $function ) : $this

Load a set of aggregations over relationship's column onto the collection.

Parameters

  • $relations array|string
  • $column string
  • $function string
public

loadCount ( $relations ) : $this

Load a set of relationship counts onto the collection.

Parameters

  • $relations array|string
public

loadMax ( $relations , $column ) : $this

Load a set of relationship's max column values onto the collection.

Parameters

  • $relations array|string
  • $column string
public

loadMin ( $relations , $column ) : $this

Load a set of relationship's min column values onto the collection.

Parameters

  • $relations array|string
  • $column string
public

loadSum ( $relations , $column ) : $this

Load a set of relationship's column summations onto the collection.

Parameters

  • $relations array|string
  • $column string
public

loadAvg ( $relations , $column ) : $this

Load a set of relationship's average column values onto the collection.

Parameters

  • $relations array|string
  • $column string
public

loadExists ( $relations ) : $this

Load a set of related existences onto the collection.

Parameters

  • $relations array|string
public

loadMissing ( $relations ) : $this

Load a set of relationships onto the collection if they are not already eager loaded.

Parameters

  • $relations array|string
protected

loadMissingRelation ( $models , array $path ) : void

Load a relationship path if it is not already eager loaded.

Parameters

public

loadMorph ( $relation , $relations ) : $this

Load a set of relationships onto the mixed relationship collection.

Parameters

  • $relation string
  • $relations array
public

loadMorphCount ( $relation , $relations ) : $this

Load a set of relationship counts onto the mixed relationship collection.

Parameters

  • $relation string
  • $relations array
public

contains ( $key , $operator , $value ) : bool

Determine if a key exists in the collection.

Parameters

  • $key mixed
  • $operator mixed
  • $value mixed
public

modelKeys ( ) : array

Get the array of primary keys.

public

merge ( $items ) : static

Merge the collection with the given items.

Parameters

public

map ( callable $callback ) : Collection |static

Run a map over each of the items.

Parameters

  • $callback callable
public

mapWithKeys ( callable $callback ) : Collection |static

Run an associative map over each of the items.

Parameters

  • $callback callable
public

fresh ( $with ) : static

Reload a fresh model instance from the database for all the entities.

Parameters

  • $with array|string
public

diff ( $items ) : static

Diff the collection with the given items.

Parameters

public

intersect ( $items ) : static

Intersect the collection with the given items.

Parameters

public

unique ( $key , $strict ) : static

Return only unique items from the collection.

Parameters

  • $key string|callable|null
  • $strict bool
public

only ( $keys ) : static

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

Parameters

  • $keys mixed
public

except ( $keys ) : static

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

Parameters

  • $keys mixed
public

makeHidden ( $attributes ) : $this

Make the given, typically visible, attributes hidden across the entire collection.

Parameters

  • $attributes array|string
public

makeVisible ( $attributes ) : $this

Make the given, typically hidden, attributes visible across the entire collection.

Parameters

  • $attributes array|string
public

append ( $attributes ) : $this

Append an attribute across the entire collection.

Parameters

  • $attributes array|string
public

getDictionary ( $items ) : array

Get a dictionary keyed by primary keys.

Parameters

public

pluck ( $value , $key ) : Collection

Get an array with the values of a given key.

Parameters

  • $value string|array
  • $key string|null
public

keys ( ) : Collection

Get the keys of the collection items.

public

zip ( $items ) : Collection

Zip the collection together with one or more arrays.

Parameters

  • $items mixed
public

collapse ( ) : Collection

Collapse the collection of items into a single array.

public

flatten ( $depth ) : Collection

Get a flattened array of the items in the collection.

Parameters

  • $depth int
public

flip ( ) : Collection

Flip the items in the collection.

public

pad ( $size , $value ) : Collection

Pad collection to the specified length with a value.

Parameters

  • $size int
  • $value mixed
protected

duplicateComparator ( $strict ) : Closure

Get the comparison function to detect duplicates.

Parameters

  • $strict bool
public

getQueueableClass ( ) : string|null

Get the type of the entities being queued.

public

getQueueableIds ( ) : array

Get the identifiers for all of the entities.

public

getQueueableRelations ( ) : array

Get the relationships of the entities being queued.

public

getQueueableConnection ( ) : string|null

Get the connection of the entities being queued.

public

toQuery ( ) : Builder

Get the Eloquent query builder from the collection.