The unless method is the logical opposite of the when method in Laravel's collection class. It executes a provided callback on the collection only if the given value evaluates to false. Additionally, you can provide a default callback to be...
The when method in Laravel's collection class executes a callback on the collection if a provided boolean value evaluates to true. It also accepts an optional default callback if the value evaluates to false. Both callbacks receive the current...
The reject method allows you to create a new Collection instance that excludes items that do not pass a given truth test. It takes a callback function as its only parameter, which determines whether each item should be included in the final...
The toArray method in Laravel's Collection class allows you to convert the collection into a plain PHP array. It not only returns the underlying array used by the collection, but also converts any object instance that implements the...
Learn how to use the mapInto method in Laravel to convert the contents of a collection to a new type. With mapInto, you can create a new instance of a specified class and supply each collection element's value and key as the arguments to the...
The jsonSerialize method in Laravel's Collection class allows you to convert the contents of a collection into a format that can be serialized using PHP's json_encode function. It follows specific rules for each element in the collection,...
Learn how to cast a Collection instance into a string in Laravel using the toJson method. When a collection is cast into a string, it returns its JSON representation. Find out how to achieve this and see an example in which a Collection with a...
Published on December 7, 2016
Published on November 29, 2016
Published on November 20, 2016