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 223<br />

.<br />

1 $unique = $collection->unique(function ($item) {<br />

2 return $item['brand'].$item['type'];<br />

3 });<br />

4<br />

5 $unique->values()->all();<br />

6<br />

7 /*<br />

8 [<br />

9 ['name' => 'iPhone 6', 'brand' => 'Apple', 'type' => 'phone'],<br />

10 ['name' => 'Apple Watch', 'brand' => 'Apple', 'type' => 'watch'],<br />

11 ['name' => 'Galaxy S6', 'brand' => 'Samsung', 'type' => 'phone'],<br />

12 ['name' => 'Galaxy Gear', 'brand' => 'Samsung', 'type' => 'watch'],<br />

13 ]<br />

14 */<br />

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

The values method returns a new collection with the keys reset to consecutive integers:<br />

.<br />

1 $collection = collect([<br />

2 10 => ['product' => 'Desk', 'price' => 200],<br />

3 11 => ['product' => 'Desk', 'price' => 200]<br />

4 ]);<br />

5<br />

6 $values = $collection->values();<br />

7<br />

8 $values->all();<br />

9<br />

10 /*<br />

11 [<br />

12 0 => ['product' => 'Desk', 'price' => 200],<br />

13 1 => ['product' => 'Desk', 'price' => 200],<br />

14 ]<br />

15 */<br />

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

The where method filters the collection by a given key / value pair:

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

Saved successfully!

Ooh no, something went wrong!