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

.<br />

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

2<br />

3 $merged = $collection->merge(['Bookcase', 'Door']);<br />

4<br />

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

6<br />

7 // ['Desk', 'Chair', 'Bookcase', 'Door']<br />

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

The pluck method retrieves all of the collection values for a given key:<br />

.<br />

1 $collection = collect([<br />

2 ['product_id' => 'prod-100', 'name' => 'Desk'],<br />

3 ['product_id' => 'prod-200', 'name' => 'Chair'],<br />

4 ]);<br />

5<br />

6 $plucked = $collection->pluck('name');<br />

7<br />

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

9<br />

10 // ['Desk', 'Chair']<br />

You may also specify how you wish the resulting collection to be keyed:<br />

.<br />

1 $plucked = $collection->pluck('name', 'product_id');<br />

2<br />

3 $plucked->all();<br />

4<br />

5 // ['prod-100' => 'Desk', 'prod-200' => 'Chair']<br />

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

The pop method removes and returns the last item from the collection:

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

Saved successfully!

Ooh no, something went wrong!