06.10.2016 Views

laravel-5

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Collections 287<br />

Available Methods<br />

For the remainder of this documentation, we’ll discuss each method available on the Collection<br />

class. Remember, all of these methods may be chained for fluently manipulating the underlying<br />

array. Furthermore, almost every method returns a new Collection instance, allowing you to<br />

preserve the original copy of the collection when necessary.<br />

You may select any method from this table to see an example of its usage:<br />

A> #collection-method-list > p { A> column-count: 3; -moz-column-count: 3; -webkitcolumn-count:<br />

3; A> column-gap: 2em; -moz-column-gap: 2em; -webkit-column-gap: 2em; A> } A><br />

A> #collection-method-list a { A> display: block; A> }<br />

<br />

<br />

all avg chunk collapse combine contains count diff diffKeys each every except filter first flatMap<br />

flatten flip forget forPage get groupBy has implode intersect isEmpty keyBy keys last map max<br />

merge min only pluck pop prepend pull push put random reduce reject reverse search shift shuffle<br />

slice sort sortBy sortByDesc splice sum take toArray toJson transform union unique values where<br />

whereStrict whereIn whereInLoose zip<br />

<br />

Method Listing<br />

A> #collection-method code { A> font-size: 14px; A> } A> A> #collection-method:not(.firstcollection-method)<br />

{ A> margin-top: 50px; A> }<br />

<br />

all() {#collection-method .first-collection-method}<br />

The all method simply returns the underlying array represented by the collection:<br />

1 collect([1, 2, 3])->all();<br />

2<br />

3 // [1, 2, 3]<br />

avg() {#collection-method}<br />

The avg method returns the average of all items in the collection:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!