Slide 1

Slide 1 text

Understanding Laravel Collections with Glenn Kimble Jr

Slide 2

Slide 2 text

What are collections?

Slide 3

Slide 3 text

What are collections? Collections are objects designed to wrap around an array and expose the operations that we can perform on that array as methods on the collection. Adam Wathan

Slide 4

Slide 4 text

What are collections? Collections are objects designed to wrap around an array and expose the operations that we can perform on that array as methods on the collection. Adam Wathan

Slide 5

Slide 5 text

● array_reduce() ○ Reduce an array of items down to a single value. ● array_map() ○ Transform data. PHP: Array Functions Allow you to interact with and manipulate arrays in various ways. ● array_filter() ○ filter out items you don’t want.

Slide 6

Slide 6 text

Why use them?

Slide 7

Slide 7 text

Why use them? 1. Method chaining. 2. Over 100 helper methods. 3. Eloquent already returns results to us as collections.

Slide 8

Slide 8 text

Method Chaining

Slide 9

Slide 9 text

Method Chaining

Slide 10

Slide 10 text

Method Chaining

Slide 11

Slide 11 text

Method Chaining: Helper Methods

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

Use collections in place of arrays

Slide 14

Slide 14 text

Use collections in place of arrays

Slide 15

Slide 15 text

Use collections in place of arrays

Slide 16

Slide 16 text

Use collections in place of arrays Implement the following: ● ArrayAccess ○ Interface to provide accessing objects as arrays. ● IteratorAggregate ○ Interface to create an external Iterator. ● Countable ○ Allows us to use php’s count() function.

Slide 17

Slide 17 text

Code Examples https://github.com/tampabaylaravel/understanding-collections/tree/master/tests/Feature