In Laravel 5

Laravel 5 Collections: Adding an Element to the Beginning of a Collection With prepend

Apr 22, 2018

The prepend method in Laravel's Collection class allows you to add a given value to the beginning of the collection. It also accepts an optional key parameter for adding items to the beginning of an associative array. The method returns a reference to the original collection instance. In the provided code examples, a new item is added to the beginning of the collection using prepend, and the resulting collection is printed. In another example, an item is added to the beginning of an associative array with a specified key using prepend, and the resulting collection is printed.
Laravel 5 Collections: Adding an Element to the End of a Collection With push

Apr 22, 2018

The push method in Laravel is used to add an item to the end of a collection. It returns a reference to the original collection instance. However, it cannot be used to set the key of the item being added. To use the push method, you create a new collection instance, and then call the push method on it, passing the item you want to add as a parameter. After the push method is executed, the collection will be modified with the new item added at the end.
Laravel 5 Collections: Adding New Elements to a Collection With put

Apr 22, 2018

The put method in the Laravel Collection class allows you to add a new item to the collection with a specified key and value. This method modifies the original Collection instance and returns a reference to it. With an example use case, you can see how the put method works in practice, by adding a new item to the collection. After executing the code, the collection would contain the added item alongside existing ones.
Laravel 5 Collections: Adding Values to a Collection With union

Apr 22, 2018

Learn how to use the union method in Laravel collections. This method adds the provided items to a copy of the existing collection, without modifying the original collection. If there are key collisions, the elements from the original collection will be used. Check out an example use case and see how union works.
Laravel 5 Collections: Breaking a Collection Into a Specified Number of Groups With split

Apr 22, 2018

The split method in Laravel is used to break a collection into a smaller number of collections. With the split method, you can specify the number of groups you want the collection split into. If there are no items in the collection, it will return a new, empty collection instance. In the example provided, a collection is split into two groups, each containing elements from the original collection.
Laravel 5 Collections: Calculating the Average Value of a Collection With average

Apr 22, 2018

The average method in PHP is an alias of the avg method. It calculates the average value of a collection and can be used in the same way. For example, you can use it to find the average of a array of numbers. Additionally, the average method can also be used with higher order messaging, which allows you to easily calculate the average price of a collection of objects using PHP's property accessors syntax.
Laravel 5 Collections: Calculating the Average Value of a Collection With avg

Apr 22, 2018

The avg method in Laravel allows you to calculate the average value of items in a collection. It can be used with both arrays and objects. You can also specify a key to average nested properties. Additionally, you can use higher order messaging to easily calculate the average of a specific property in a collection of objects.
Laravel 5 Collections: Calculating the Median Value of a Collection With median

Apr 22, 2018

The median method in PHP can be used to calculate the median value of a collection of data. It allows you to find the value that separates the higher and lower halves of the data. You can also specify a key to limit the calculation to nested property values. In the provided example, the median method is used to find the median value of both a collection of numbers and a collection of test scores.
Laravel 5 Collections: Calculating the Minimum Value of a Collection With min

Apr 22, 2018

The min method in Laravel is the opposite of the max method and accepts the same number of arguments. It can be used to retrieve the minimum value of a given key. If no key is specified, it will function similarly to PHP's min function. In the code examples provided, it shows how to use the min method both with and without specifying a key.
Laravel 5 Collections: Calculating the Sum of a Collection With sum

Apr 22, 2018

The sum method in Laravel's Collection class returns the sum of all items in the collection. It can also accept a callback function to specify which values should be added together. If the collection is empty, the method will return 0. In the first example, the code shows a simple usage of the sum method to calculate the sum of numbers in the collection. In the second example, the code demonstrates how to use the sum method to calculate the total number of speakers at a conference. The third example shows how the sum method can be used with a higher order message to calculate the sum of speakers at multiple conferences.
Laravel 5 Collections: Checking If a Collection Contains Items With isEmpty

Apr 22, 2018

The isEmpty method in Laravel's Collection class can be used to determine if a collection contains any items. If the collection is empty, true is returned; otherwise, false is returned. You can use this method to check if a collection has items before performing any operations on it.
Laravel 5 Collections: Checking If a Collection Contains Items With isNotEmpty

Apr 22, 2018

The isNotEmpty method is used to determine whether a collection is not empty. This method returns a boolean value indicating whether the collection has any items or not. You can use this method to easily check if a collection contains any elements.
Laravel 5 Collections: Combining Collection Elements Into a String With implode

Apr 22, 2018

The implode method in Laravel combines the items of a collection together, with the option to specify a "glue" between each item. Unlike PHP's implode function, Laravel's Collection allows for operating on arrays of primitive data types as well as arrays of objects and arrays. The returned value is a string with the specified glue between each item. Examples demonstrate how to use implode with both simple arrays and collections containing arrays or objects.
Laravel 5 Collections: Combining the Keys of a Collection With the Values of Another Collection With combine

Apr 22, 2018

The combine method in Laravel is used to combine the keys of a collection with the values of another collection or array. It returns a new Collection instance without modifying the original collection. Both collections or arrays must have the same length, otherwise an error will be thrown. This method is similar to PHP's array_combine function.

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.