The toJson method allows you to convert the data stored in a collection instance into a JSON-encoded string. It internally makes a call to PHP's json_encode function, using any $options that were supplied. If a well-formatted value is desired, the...
The collapse method in Laravel combines all the first-level items of a collection into a new, single collection. It does not recursively collapse inner arrays, but it can collapse both nested arrays and Collection instances. This method can be...
The toBase method in PHP returns a new collection instance that contains all the data from the current collection. This is useful when you want to modify the collection without changing the original instance. For example, you can create a new...
The crossJoin method in PHP allows you to join the items within a collection with the values of input arrays or collections. This produces a Cartesian product, which can be useful for various applications. In the provided example, the method is...
The diff method in Laravel is used to find the items in a collection that are not present in another collection or an array. It returns a new instance of a collection.
The containsStrict method in Laravel acts as a shortcut to the contains method with a strict comparison operator. It is used to check if a collection contains a given value using strict comparison. The method can be used with both key-value pairs...
The contains method is used to check if a given key or key/value pair exists within a collection. It is versatile and can be used with different types of data, such as arrays and objects. You can also provide a function as an argument to perform...
Published on April 22, 2018
Published on December 5, 2021
Published on November 29, 2016