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

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

The flip method swaps the collection’s keys with their corresponding values:<br />

1 $collection = collect(['name' => 'taylor', 'framework' => '<strong>laravel</strong>']);<br />

2<br />

3 $flipped = $collection->flip();<br />

4<br />

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

6<br />

7 // ['taylor' => 'name', '<strong>laravel</strong>' => 'framework']<br />

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

The forget method removes an item from the collection by its key:<br />

1 $collection = collect(['name' => 'taylor', 'framework' => '<strong>laravel</strong>']);<br />

2<br />

3 $collection->forget('name');<br />

4<br />

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

6<br />

7 // ['framework' => '<strong>laravel</strong>']<br />

Note: Unlike most other collection methods, forget does not return a new modified<br />

collection; it modifies the collection it is called on.<br />

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

The forPage method returns a new collection containing the items that would be present on a given<br />

page number:

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

Saved successfully!

Ooh no, something went wrong!