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 307<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']<br />

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

The push method appends an item to the end of the collection:<br />

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

2<br />

3 $collection->push(5);<br />

4<br />

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

6<br />

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

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

The put method sets the given key and value in the collection:<br />

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

2<br />

3 $collection->put('price', 100);<br />

4<br />

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

6<br />

7 // ['product_id' => 1, 'name' => 'Desk', 'price' => 100]

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

Saved successfully!

Ooh no, something went wrong!