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

12 */<br />

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

The keys method returns all of the collection’s keys:<br />

1 $collection = collect([<br />

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

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

4 ]);<br />

5<br />

6 $keys = $collection->keys();<br />

7<br />

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

9<br />

10 // ['prod-100', 'prod-200']<br />

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

The last method returns the last element in the collection that passes a given truth test:<br />

1 collect([1, 2, 3, 4])->last(function ($value, $key) {<br />

2 return $value < 3;<br />

3 });<br />

4<br />

5 // 2<br />

You may also call the last method with no arguments to get the last element in the collection. If<br />

the collection is empty, null is returned:<br />

1 collect([1, 2, 3, 4])->last();<br />

2<br />

3 // 4

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

Saved successfully!

Ooh no, something went wrong!