In Laravel 5

Laravel 5 Collections: Retrieving the Maximum Value of a Collection With max

Apr 22, 2018

The max method in Laravel can be used to retrieve the maximum value of a given key. By default, the key is null and it behaves similarly to PHP's max function. In the first example, without specifying a key, the method returns the maximum value from the collection. In the second example, a key is specified and the method returns the maximum value based on that key.
Laravel 5 Collections: Returning Collection Elements That Are Not Present in the Specified Collections With diffAssoc

Apr 22, 2018

The diffAssoc method in Laravel returns a new collection containing the items where the keys and values are not present in the provided arguments. It is similar to PHP's array_diff_assoc function. In the example usage, $newInformation will store any new information from the $contactInformation collection that is not found in the provided arguments.
Laravel 5 Collections: Reversing the Order of Collection Elements With reverse

Apr 22, 2018

Learn about the reverse method in Laravel's Collection class. This method is used to reverse the order of items in a collection. It returns a new Collection instance that contains the reversed items. The numerical keys are not preserved, but non-numerical keys are preserved.
Laravel 5 Collections: Sort a Collection in Descending Order With sortByDesc

Apr 22, 2018

The sortByDesc method is similar to the sortBy method, but it does not have a $descending parameter. Instead, it internally calls the sortBy method with true as the argument for the $descending parameter. Both methods allow you to sort a collection based on a callback function or a property. You can also use the sortByDesc method with higher order messages, allowing you to sort a collection in reverse order based on a property.
Laravel 5 Collections: Sorting a Collection Based on a Key Value With sortBy

Apr 22, 2018

The sortBy method in Laravel allows you to sort a collection by a key or a value returned by a callback function. You can modify the sorting behavior using the $options parameter and choose whether to sort in ascending or descending order with the $descending parameter. The method returns a new instance of the Collection class with the items sorted and does not modify the original collection. Examples demonstrate sorting by name, number of followers, and using different sorting flags such as SORT_NUMERIC and SORT_STRING.
Laravel 5 Collections: Sorting a Collection With sort

Apr 22, 2018

The sort method is used to sort a collection. By default, it uses a case-insensitive "natural order" algorithm. You can also provide a custom comparison function as an argument to the method. The original collection remains unchanged, and the method returns a new instance of Collection. The keys of the collection items are preserved during sorting. In the examples provided, the sort method is used to sort a collection of numbers in ascending order and a collection of people based on their age.
Laravel 5 Collections: Splitting a Collection Into Smaller Pieces With chunk

Apr 22, 2018

The chunk method in PHP is used to create smaller collections from larger collections. It takes two parameters: $size to control the size of each new collection, and $preserveKeys to indicate if the method should preserve array keys. By default, the method does not preserve array keys, but passing true as the second argument will include the original array keys in the resulting collections.
Laravel 5 Collections Static API: Adding Methods to the Higher Order Message List With proxy

Apr 22, 2018

The proxy static method in Laravel's Collection class allows you to add additional methods to the list of methods that should be proxied for use with higher order messaging. These methods provide a cleaner syntax when invoking methods on collections of objects. For example, you can add the contains method to the list of proxied methods and then invoke it on a collection of objects using the -> syntax. Internally, the contains method will be executed on each object instance in the collection.
Laravel 5 Collections Static API: Creating a Collection By Invoking a Callback a Given Number of Times With times

Apr 22, 2018

Learn how to use the times static method in Laravel's Collection class to easily create collections with a specified number of elements. The times method is similar to PHP's range function, but it provides additional functionality for collections. You can pass a $number argument to specify the number of elements and an optional $callback function to modify each element. Discover how to use the times method to populate a collection with a range of numbers or create a collection of Carbon date instances for the next few days. Be aware of potential duplicate dates when using the times method and consider storing the current date outside of the callback function.
Laravel 5 Collections Static API: Creating a New Collection Instance From Arrays Using make

Apr 22, 2018

The make static method in Laravel's Collection class creates a new collection instance with the provided items. If the argument is already a collection instance, it will be returned as is. You can use this method to easily create collections in your code. For example, you can create a collection from an array of items using Collection::make($items), and it will return a new collection instance.
Laravel 5 Collections Static API: Ensure a Value Is a Collection With wrap

Apr 22, 2018

The wrap static method in the Illuminate\Support\Collection class creates a collection from any value supplied to it. It is useful in situations where a collection instance is expected. For example, it can be used to ensure that function or method arguments are always a collection. It does not wrap a value if it is already a collection.
Laravel 5 Collections Static API: Returning the Items of a Collection With unwrap

Apr 22, 2018

The unwrap method in Laravel's Collection class allows you to access the underlying items of a collection. If the value provided is already a collection, its underlying items will be returned. If the value is not a collection, the value will be returned as is. This method can be useful when you want to ensure that an argument supplied to a function is always an array.
Laravel 5 Collections: Swapping Element Keys and Values With flip

Apr 22, 2018

The flip method in Laravel's Collection class returns a new instance of Collection with the keys and values swapped. It is similar to PHP's array_flip function. Using this method, you can easily reverse the order of items in a collection.
Laravel 5 Collections: Testing All Collection Values With every

Apr 22, 2018

The every method in Laravel is used to determine if each element of a collection passes a given truth test. It can accept a callback function or an operator and comparison value. For example, it can be used to check if all input characters are alphabetic or if all users in a collection are verified. It supports various operators like equality, not equal, less than, greater than, etc. The every method can also be used with higher order messaging to access properties on objects.

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.