Laravel Collections – Introduction to Collections

Laravel Collections

Laravel Collections are one of the most powerful features of Laravel. Basically, collections are PHP arrays but it’s an Object Oriented approach to deal with PHP arrays.

Laravel collections offer over 90+ methods for manipulating the underlying data set. All methods are chainable, which means you can write code which is readable.

In this series, we will learn everything about the collection and what we can achieve with them. This post is an introduction to Laravel Collections, in the following posts, we will dive into the all methods Laravel Collections supplies with real examples.

Static Functions

Laravel’s Collection class ( Illuminate\Support\Collection ), provides some static functions which we can use to create new collection instances. Which are…

  • Collection::make();
  • Collection::wrap();
  • Collection::unwrap();
  • Collection::times();
  • Collection::proxy();

Public Functions

Laravel’s Collection class also expose the public API which provides many public methods that allow you to manipulate and transform the collections internal elements.

You can find all the public methods in the Illuminate\Support\Collection class or you can read the documentation for all function here.

We will be taking some real examples and use the collection methods to interact with the data.

So stay tuned for upcoming posts of this series.

Your little help will keep this site alive and help us to produce quality content for you.