Articles

Laravel 5 Collections: Conditionally Executing a Callback On a Collection's Elements With unless

Laravel 5 The unless method is the logical opposite of the when method. The unless method will execute the provided $callback on the collection; if the provided $value evaluates to false. A $default callback may also be...

Laravel 5 Collections: Conditionally Executing a Callback On a Collection's Elements With when

Laravel 5 The when method will execute the provided $callback on the collection if the provided boolean $value evaluates to true. A $default callback may also be supplied if the provided $value evaluates to false. Both...

Laravel 5 Collections: Conditionally Removing Elements From a Collection With reject

Laravel 5 The reject method used to create a new Collection instance containing all the items in the collection that do not pass a given truth test. The reject method only defines one parameter: $callback. The...

Laravel 5 Collections: Convert a Collection to a Native PHP Array With toArray

Laravel 5 The toArray method is similar to the all method in that it will return the underlying array that the collection instance is using. The difference, however, is that the toArray method will convert any object...

Laravel 5 Collections: Convert Collection Elements Into Object Instances With mapInto

Laravel 5 The mapInto method is similar to the transform method in that allows you to quickly convert, or project, the contents of the collection to a new type. However, instead of building up the resulting type instance...