29.07.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 210<br />

.<br />

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

2<br />

3 $collection->pop();<br />

4<br />

5 // 5<br />

6<br />

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

8<br />

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

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

The prepend method adds an item to the beginning of the collection:<br />

.<br />

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

2<br />

3 $collection->prepend(0);<br />

4<br />

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

6<br />

7 // [0, 1, 2, 3, 4, 5]<br />

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

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

.<br />

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

2<br />

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

4<br />

5 // 'Desk'<br />

6<br />

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

8<br />

9 // ['product_id' => 'prod-100']

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

Saved successfully!

Ooh no, something went wrong!