06.10.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 306<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 />

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

You can optionally pass a second argument to set the key of the prepended item:<br />

1 $collection = collect(['one' => 1, 'two', => 2]);<br />

2<br />

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

4<br />

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

6<br />

7 // ['zero' => 0, 'one' => 1, 'two', => 2]<br />

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

The pull method removes and returns an item from the collection by its key:

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

Saved successfully!

Ooh no, something went wrong!