class Illuminate / Support / LazyCollection
You are viewing an older version of the documentation. For the latest, please visit master documentation.

LazyCollection

Implements

Uses

Properties

public

$source callable|static

The source from which to generate items.

Default: null

Methods

public

__construct ( $source ) : void

Create a new lazy collection instance.

Parameters

  • $source mixed
public static

range ( $from , $to ) : static

Create a collection with the given range.

Parameters

  • $from int
  • $to int
public

all ( ) : array

Get all items in the enumerable.

public

eager ( ) : static

Eager load all items into a new lazy collection backed by an array.

public

remember ( ) : static

Cache values as they're enumerated.

public

avg ( $callback ) : mixed

Get the average value of a given key.

Parameters

  • $callback callable|string|null
public

median ( $key ) : mixed

Get the median of a given key.

Parameters

  • $key string|array|null
public

mode ( $key ) : array|null

Get the mode of a given key.

Parameters

  • $key string|array|null
public

collapse ( ) : static

Collapse the collection of items into a single array.

public

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

Determine if an item exists in the enumerable.

Parameters

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

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

Determine if an item is not contained in the enumerable.

Parameters

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

crossJoin ( $arrays ) : static

Cross join the given iterables, returning all possible permutations.

Parameters

  • $arrays array
public

countBy ( $countBy ) : static

Count the number of items in the collection by a field or using a callback.

Parameters

  • $countBy callable|string
public

diff ( $items ) : static

Get the items that are not present in the given items.

Parameters

  • $items mixed
public

diffUsing ( $items , callable $callback ) : static

Get the items that are not present in the given items, using the callback.

Parameters

  • $items mixed
  • $callback callable
public

diffAssoc ( $items ) : static

Get the items whose keys and values are not present in the given items.

Parameters

  • $items mixed
public

diffAssocUsing ( $items , callable $callback ) : static

Get the items whose keys and values are not present in the given items, using the callback.

Parameters

  • $items mixed
  • $callback callable
public

diffKeys ( $items ) : static

Get the items whose keys are not present in the given items.

Parameters

  • $items mixed
public

diffKeysUsing ( $items , callable $callback ) : static

Get the items whose keys are not present in the given items, using the callback.

Parameters

  • $items mixed
  • $callback callable
public

duplicates ( $callback , $strict ) : static

Retrieve duplicate items.

Parameters

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

duplicatesStrict ( $callback ) : static

Retrieve duplicate items using strict comparison.

Parameters

  • $callback callable|string|null
public

except ( $keys ) : static

Get all items except for those with the specified keys.

Parameters

  • $keys mixed
public

filter ( callable $callback ) : static

Run a filter over each of the items.

Parameters

  • $callback callable|null
public

first ( callable $callback , $default ) : mixed

Get the first item from the enumerable passing the given truth test.

Parameters

  • $callback callable|null
  • $default mixed
public

flatten ( $depth ) : static

Get a flattened list of the items in the collection.

Parameters

  • $depth int
public

flip ( ) : static

Flip the items in the collection.

public

get ( $key , $default ) : mixed

Get an item by key.

Parameters

  • $key mixed
  • $default mixed
public

groupBy ( $groupBy , $preserveKeys ) : static

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

Parameters

  • $groupBy array|callable|string
  • $preserveKeys bool
public

keyBy ( $keyBy ) : static

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

Parameters

  • $keyBy callable|string
public

has ( $key ) : bool

Determine if an item exists in the collection by key.

Parameters

  • $key mixed
public

hasAny ( $key ) : bool

Determine if any of the keys exist in the collection.

Parameters

  • $key mixed
public

implode ( $value , $glue ) : string

Concatenate values of a given key as a string.

Parameters

  • $value string
  • $glue string|null
public

intersect ( $items ) : static

Intersect the collection with the given items.

Parameters

  • $items mixed
public

intersectByKeys ( $items ) : static

Intersect the collection with the given items by key.

Parameters

  • $items mixed
public

isEmpty ( ) : bool

Determine if the items are empty or not.

public

containsOneItem ( ) : bool

Determine if the collection contains a single item.

public

join ( $glue , $finalGlue ) : string

Join all items from the collection using a string. The final items can use a separate glue string.

Parameters

  • $glue string
  • $finalGlue string
public

keys ( ) : static

Get the keys of the collection items.

public

last ( callable $callback , $default ) : mixed

Get the last item from the collection.

Parameters

  • $callback callable|null
  • $default mixed
public

pluck ( $value , $key ) : static

Get the values of a given key.

Parameters

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

map ( callable $callback ) : static

Run a map over each of the items.

Parameters

  • $callback callable
public

mapToDictionary ( callable $callback ) : static

Run a dictionary map over the items.

Parameters

  • $callback callable
public

mapWithKeys ( callable $callback ) : static

Run an associative map over each of the items.

Parameters

  • $callback callable
public

merge ( $items ) : static

Merge the collection with the given items.

Parameters

  • $items mixed
public

mergeRecursive ( $items ) : static

Recursively merge the collection with the given items.

Parameters

  • $items mixed
public

combine ( $values ) : static

Create a collection by using this collection for keys and another for its values.

Parameters

  • $values mixed
public

union ( $items ) : static

Union the collection with the given items.

Parameters

  • $items mixed
public

nth ( $step , $offset ) : static

Create a new collection consisting of every n-th element.

Parameters

  • $step int
  • $offset int
public

only ( $keys ) : static

Get the items with the specified keys.

Parameters

  • $keys mixed
public

concat ( $source ) : static

Push all of the given items onto the collection.

Parameters

  • $source iterable
public

random ( $number ) : static|mixed

Get one or a specified number of items randomly from the collection.

Parameters

  • $number int|null
public

replace ( $items ) : static

Replace the collection items with the given items.

Parameters

  • $items mixed
public

replaceRecursive ( $items ) : static

Recursively replace the collection items with the given items.

Parameters

  • $items mixed
public

reverse ( ) : static

Reverse items order.

public

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

Parameters

  • $value mixed
  • $strict bool
public

shuffle ( $seed ) : static

Shuffle the items in the collection.

Parameters

  • $seed int|null
public

sliding ( $size , $step ) : static

Create chunks representing a "sliding window" view of the items in the collection.

Parameters

  • $size int
  • $step int
public

skip ( $count ) : static

Skip the first {$count} items.

Parameters

  • $count int
public

skipUntil ( $value ) : static

Skip items in the collection until the given condition is met.

Parameters

  • $value mixed
public

skipWhile ( $value ) : static

Skip items in the collection while the given condition is met.

Parameters

  • $value mixed
public

slice ( $offset , $length ) : static

Get a slice of items from the enumerable.

Parameters

  • $offset int
  • $length int|null
public

split ( $numberOfGroups ) : static

Split a collection into a certain number of groups.

Parameters

  • $numberOfGroups int
public

sole ( $key , $operator , $value ) : mixed

Get the first item in the collection, but only if exactly one item exists. Otherwise, throw an exception.

Parameters

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

firstOrFail ( $key , $operator , $value ) : mixed

Get the first item in the collection but throw an exception if no matching items exist.

Parameters

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

chunk ( $size ) : static

Chunk the collection into chunks of the given size.

Parameters

  • $size int
public

splitIn ( $numberOfGroups ) : static

Split a collection into a certain number of groups, and fill the first groups completely.

Parameters

  • $numberOfGroups int
public

chunkWhile ( callable $callback ) : static

Chunk the collection into chunks with a callback.

Parameters

  • $callback callable
public

sort ( $callback ) : static

Sort through each item with a callback.

Parameters

  • $callback callable|null|int
public

sortDesc ( $options ) : static

Sort items in descending order.

Parameters

  • $options int
public

sortBy ( $callback , $options , $descending ) : static

Sort the collection using the given callback.

Parameters

  • $callback callable|string
  • $options int
  • $descending bool
public

sortByDesc ( $callback , $options ) : static

Sort the collection in descending order using the given callback.

Parameters

  • $callback callable|string
  • $options int
public

sortKeys ( $options , $descending ) : static

Sort the collection keys.

Parameters

  • $options int
  • $descending bool
public

sortKeysDesc ( $options ) : static

Sort the collection keys in descending order.

Parameters

  • $options int
public

sortKeysUsing ( callable $callback ) : static

Sort the collection keys using a callback.

Parameters

  • $callback callable
public

take ( $limit ) : static

Take the first or last {$limit} items.

Parameters

  • $limit int
public

takeUntil ( $value ) : static

Take items in the collection until the given condition is met.

Parameters

  • $value mixed
public

takeUntilTimeout ( DateTimeInterface $timeout ) : static

Take items in the collection until a given point in time.

Parameters

public

takeWhile ( $value ) : static

Take items in the collection while the given condition is met.

Parameters

  • $value mixed
public

tapEach ( callable $callback ) : static

Pass each item in the collection to the given callback, lazily.

Parameters

  • $callback callable
public

undot ( ) : static

Convert a flatten "dot" notation array into an expanded array.

public

unique ( $key , $strict ) : static

Return only unique items from the collection array.

Parameters

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

values ( ) : static

Reset the keys on the underlying array.

public

zip ( $items ) : static

Zip the collection together with one or more arrays.

Parameters

  • $items mixed
public

pad ( $size , $value ) : static

Pad collection to the specified length with a value.

Parameters

  • $size int
  • $value mixed
public

getIterator ( ) : Traversable

Get the values iterator.

public

count ( ) : int

Count the number of items in the collection.

protected

makeIterator ( $source ) : Traversable

Make an iterator from the given source.

Parameters

  • $source mixed
protected

explodePluckParameters ( $value , $key ) : array

Explode the "value" and "key" arguments passed to "pluck".

Parameters

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

passthru ( $method , array $params ) : static

Pass this lazy collection through a method on the collection class.

Parameters

  • $method string
  • $params array
protected

now ( ) : int

Get the current time.