In Laravel 5

Laravel 5 Collections: Determining If a Collection Contains an Element With contains

Apr 22, 2018

The contains method is used to check if a given key or key/value pair exists within a collection. It is versatile and can be used with different types of data, such as arrays and objects. You can also provide a function as an argument to perform custom truth tests. However, be careful when using the method with null as the second argument, as it will always return true. Additionally, you can use the contains method in conjunction with higher order messaging to access properties and invoke methods on objects within a collection.
Laravel 5 Collections: Determining If a Collection Has An Element With has

Apr 22, 2018

The has method in Laravel's Collection class allows you to check if an item exists in the collection based on a given key. It returns true if the item exists and false if it does not. You can easily use this method to determine the presence of specific items in your collection.
Laravel 5 Collections: Determining the Most Common Value in a Collection With mode

Apr 22, 2018

The mode method in PHP's collection class allows you to find the value that appears most often in a dataset. You can optionally specify a key to determine the mode based on specific data fields. For example, you can find the most common number of employees in a collection of department data.
Laravel 5 Collections: Dumping the Collection Contents and Continuing Script Execution for Debugging With dump

Apr 22, 2018

The dump method in Laravel is used to display the contents of a collection for debugging purposes. Unlike the dd method, the dump method does not stop the execution of the script. It behaves similarly to PHP's var_dump function.
Laravel 5 Collections: Dumping the Collection Contents and Stopping Script Execution for Debugging With dd

Apr 22, 2018

The dd method in Laravel dumps the contents of a collection and stops the execution of the script. It acts exclusively on the collection's internal array and provides a helpful way to debug your code. You can use it to inspect the contents of a collection during development and ensure the correct data is being stored.
Laravel 5 Collections: Ensuring a Collection Always Contains a Specified Number of Elements With pad

Apr 22, 2018

The pad method pads the elements of the collection up to the desired size with the specified value. It returns a new collection without modifying the original collection. The behavior of this method is similar to PHP's array_pad function. In the example, we create an initial collection and then create two new padded collections, demonstrating the different results between padding an existing collection and padding a new collection.
Laravel 5 Collections: Excluding Collection Elements With except

Apr 22, 2018

The except method in Laravel allows you to retrieve all key/value pairs from a collection except for the ones specified in the given array. You can easily remove sensitive data by combining except with the toJson method and send the modified information to an end user. See code examples for more details.
Laravel 5 Collections: Execute a Callback on the Collection Instance While Returning the Original Collection Instance With tap

Apr 22, 2018

The tap method in PHP allows you to supply a callback that receives a copy of the current collection instance. The original collection is not modified, but the callback can perform actions on the copied version and return a reference to the original collection. In the provided example, the tap method is used to access a copy of the original collection, transform its items to uppercase, and return an array containing the unchanged original collection items.
Laravel 5 Collections: Executing a Function on a Collection and Returning the Function Results With pipe

Apr 22, 2018

The pipe method in Laravel allows you to execute a callback function on a copy of a collection and returns the result of the callback. In the provided example, the pipe method is used to calculate the median value of a collection. Another example demonstrates how to retrieve weather forecasts from the Yahoo Weather API for a collection of locations using the pipe method. The getForecasts function uses the pipe method to gather weather forecasts and return a new collection instance with the locations and forecasts.
Laravel 5 Collections: Executing a Function On All Collection Elements With each

Apr 22, 2018

The each method in Laravel's Collection class allows you to iterate over each element in the collection and perform a callback function on it. If the callback function returns false, the iteration will stop. You can use the each method to modify the properties of objects within the collection. Additionally, you can use higher order messaging to invoke methods on objects in the collection without explicitly writing a callback function.
Laravel 5 Collections: Executing a Function on Collection Elements and Values With mapSpread

Apr 22, 2018

The mapSpread method in PHP is used to execute a callback on a collection, allowing you to work with nested collections or Traversable objects. This method returns a new collection without modifying the original one. You can use mapSpread to replicate the behavior of LINQ's Zip operator, which combines two collections and applies a function to create a new collection.
Laravel 5 Collections: Executing a Function on Collection Elements With eachSpread

Apr 22, 2018

The eachSpread method allows you to execute a callback function on each element in a collection, using the element's values as arguments. You can stop iterating the collection by returning false from the callback function.
Laravel 5 Collections: Filtering a Collection Based On Key Presence Using Strict Comparison Operators With whereInStrict

Apr 22, 2018

The whereInStrict method is used to determine the collection elements that match a key-value pair using strict comparison. This method returns a new collection without modifying the original one. For example, if we have a collection of people with different age values including integers and strings, we can use whereInStrict or whereIn with strict mode to retrieve elements based on a specific age value.
Laravel 5 Collections: Filtering a Collection Based On Key Presence Using Strict Comparison Operators With whereNotInStrict

Apr 22, 2018

The whereNotInStrict method filters a collection to return all items that do not have matching values for a given key. This method can be used with arrays and objects alike, and it performs strict comparisons. The original collection is not modified. An example use case is filtering a collection of users to only include those who are not banned.

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.