29.07.2016 Views

laravel-5

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Collections 197<br />

.<br />

1 @foreach ($products->chunk(3) as $chunk)<br />

2 <br />

3 @foreach ($chunk as $product)<br />

4 {{ $product->name }}<br />

5 @endforeach<br />

6 <br />

7 @endforeach<br />

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

The collapse method collapses a collection of arrays into a flat collection:<br />

.<br />

1 $collection = collect([[1, 2, 3], [4, 5, 6], [7, 8, 9]]);<br />

2<br />

3 $collapsed = $collection->collapse();<br />

4<br />

5 $collapsed->all();<br />

6<br />

7 // [1, 2, 3, 4, 5, 6, 7, 8, 9]<br />

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

The contains method determines whether the collection contains a given item:<br />

.<br />

1 $collection = collect(['name' => 'Desk', 'price' => 100]);<br />

2<br />

3 $collection->contains('Desk');<br />

4<br />

5 // true<br />

6<br />

7 $collection->contains('New York');<br />

8<br />

9 // false<br />

You may also pass a key / value pair to the contains method, which will determine if the given pair<br />

exists in the collection:

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

Saved successfully!

Ooh no, something went wrong!