Articles

Laravel 5 Collections: Ensuring a Collection Always Contains a Specified Number of Elements With pad

Laravel 5 The pad method will pad the current collection instance's elements up to the provided size with the given value (based on the integer size of the collection). This method will return a new collection instance...

Laravel 5 Collections: Excluding Collection Elements With except

Laravel 5 The except method will return all the key/value pairs in the collection where the keys in the collection are not in the supplied $keys array. Internally, this method makes a call to the...

Laravel 5 Collections: Execute a Callback on the Collection Instance While Returning the Original Collection Instance With tap

Laravel 5 The tap method will allow you supply a callback that will receive a copy of the current collection instance. The user supplied function will not modify the original collection, but will return a...

Laravel 5 Collections: Executing a Function on a Collection and Returning the Function Results With pipe

Laravel 5 The pipe method is similar to the tap method in that it executes the provided $callback function on a copy of the collection; however, unlike the tap method, the pipe method returns the result of the callback...

Laravel 5 Collections: Executing a Function On All Collection Elements With each

Laravel 5 The each method accepts a $callback which will be called on each item in the collection. If the $callback returns false, the each method will break from its iterator and return a reference back to the original...