Search

Showing 7 of 587 result(s)

/blog/2018/04/22/laravel-5-collections-calculating-the-sum-of-a-collection-with-sum

The sum is a simple method that returns the sum of all items in a collection. It also defines a $callback parameter which can be used to tell the sum method which values of the collection should be added together. If no items are in the...

/blog/2018/04/22/laravel-5-collections-calculating-the-sum-of-a-collection-with-sum#content-signature

The following code example shows the simplest way to use the sum method: After the above code has executed, the $sum variable will contain the value 15 , which is indeed the sum of all the items in the collection. The following is a more...

/blog/2018/04/22/laravel-5-collections-calculating-the-sum-of-a-collection-with-sum#content-using-sum-with-higher-order-messages

Higher order messages are a concept that allows you to invoke methods on objects within a collection using property accessors syntax. The following example will use the Laracon EU collection be built in the previous section. We will create a new...

/blog/2018/04/22/laravel-5-collections-conditionally-removing-elements-from-a-collection-with-reject#content-using-reject-with-higher-order-messages

The reject method can also be used with higher order messaging, which allows us to invoke collection methods and access properties on objects using PHP's property accessors syntax. In the following example, we will create a simple Product class...

/blog/2018/04/22/laravel-5-collections-executing-a-function-on-collection-elements-with-eachspread

The eachSpread method is used to execute the provided $callback function on each element in the collection. The element's values will become arguments to the callback function.The following example demonstrates the use of the eachSpread method:...

/blog/2018/04/22/laravel-5-collections-filtering-a-collection-based-on-key-presence-with-wherein

The whereIn method is used to filter the collection based on a given $key and an array of the possible $values that the $key can have. The method also defines an optional $strict parameter, which when an argument with a truth value of true is...

/blog/2018/04/22/laravel-5-collections-filtering-a-collection-based-on-key-presence-with-wherenotin

The whereNotIn method will return all of the items in a collection that do not have matching values (supplied via the $values parameter) for the provided $key . This method is capable of filtering collections of both arrays and objects. The...