Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Understanding Laravel Collections

Understanding Laravel Collections

A simple guide to familiarizing yourself with Laravel's collection methods.

The full video (including code examples) can be seen at https://www.youtube.com/watch?v=2aYlruGdo8g

Code can be viewed at https://github.com/tampabaylaravel/understanding-collections/tree/master/tests/Feature

Follow me on Twitter @GlennKimbleJr
https://twitter.com/GlennKimbleJr

Glenn Kimble Jr

July 16, 2019
Tweet

Other Decks in Programming

Transcript

  1. 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
  2. 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
  3. • 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.
  4. Why use them? 1. Method chaining. 2. Over 100 helper

    methods. 3. Eloquent already returns results to us as collections.
  5. 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.