06.10.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 299<br />

1 $grouped = $collection->groupBy(function ($item, $key) {<br />

2 return substr($item['account_id'], -3);<br />

3 });<br />

4<br />

5 $grouped->toArray();<br />

6<br />

7 /*<br />

8 [<br />

9 'x10' => [<br />

10 ['account_id' => 'account-x10', 'product' => 'Chair'],<br />

11 ['account_id' => 'account-x10', 'product' => 'Bookcase'],<br />

12 ],<br />

13 'x11' => [<br />

14 ['account_id' => 'account-x11', 'product' => 'Desk'],<br />

15 ],<br />

16 ]<br />

17 */<br />

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

The has method determines if a given key exists in the collection:<br />

1 $collection = collect(['account_id' => 1, 'product' => 'Desk']);<br />

2<br />

3 $collection->has('email');<br />

4<br />

5 // false<br />

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

The implode method joins the items in a collection. Its arguments depend on the type of items in<br />

the collection.<br />

If the collection contains arrays or objects, you should pass the key of the attributes you wish to<br />

join, and the “glue” string you wish to place between the values:

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

Saved successfully!

Ooh no, something went wrong!