Laravel Collections – make Method

laravel collection make method

This post is part of the series Laravel Collection

Other posts in this series:

  1. Laravel Collections – Introduction to Collections
  2. Laravel Collections – make Method (Current)
  3. Laravel Collections – wrap() and unwrap() Methods

Laravel Collections Illuminate\Support\Collection class provides number of static helper functions that help us to create new instance of collection.

Static API’s make method creates a new instance of a collection with the provided array.

Signature – Laravel Collections

Below is the signature of make method defined in Illuminate\Support\Collection class.

Usage – Laravel Collections

Let’s create a new collection from an array and check if it is an instance of the collection class.

Assume we have a very simple array like below.

We can convert the above array to a collection using make() method of collection class like below.

With above code example, our $languages array is converted to a collection and stored in $collection variable.

We can check if the $collection is an instance of collection class like below.

If $collection is a collection then it will return true.

Continue reading this series: