In Laravel

Laravel Collection Public API: each

Nov 29, 2016

The each method in Laravel's Collection class allows you to perform a $callback on each item in the collection. If the $callback function returns false, the loop will break. This method is similar to PHP's foreach construct. Even though the each method does not explicitly allow modifications to a collection's items, it is still possible to modify object properties within the collection due to how PHP treats objects as references. Keep in mind that the each method modifies the original collection and does not return a modified copy.
Laravel Collection Public API: filter

Nov 29, 2016

The filter method is used to apply a filter to a collection in Laravel. You can provide your own truth tests using a callback function to determine if a value should be included in the final collection. By default, any value that evaluates to false will be removed from the collection. The method returns a modified copy of the original collection without modifying the original.
Laravel Collection Public API: first

Nov 29, 2016

The first method in Laravel's Collection class is used to retrieve the first item in a collection. You can also pass a callback function to specify criteria for selecting the first item. If there are no items that match the criteria, you can provide a default value to be returned.
Laravel Collection Public API: flatMap

Nov 29, 2016

The flatMap method in Laravel is similar to map, but it collapses the resulting collection. It is used to transform each item in the collection and then merge the results into a single collection. This can be demonstrated by comparing two code examples that achieve the same result: mapping each item to uppercase.
Laravel Collection Public API: flatten

Nov 29, 2016

The flatten method in Laravel's Collection class allows you to transform a nested collection into a single-dimensional collection. This method does not preserve any keys from the original collection, even for deeply nested arrays.
Laravel Collection Public API: flip

Nov 29, 2016

The flip method in Laravel allows you to exchange keys with their corresponding values in a Collection. This can be useful when you need to perform operations based on the values rather than the keys. In the provided example, the $flippedCollection variable will contain a new instance of the Collection class where the original keys have been swapped with their corresponding values.
Laravel Collection Public API: forget

Nov 29, 2016

The forget method in Laravel can be used to remove an item from a collection based on a given key or numerical index. It modifies the collection instance it was called on. You can use the forget method to easily remove items from a collection and maintain the collection's structure and integrity.
Laravel Collection Public API: forPage

Nov 29, 2016

The forPage method in Laravel is used for implementing pagination over collections. This method takes two parameters: the page number and the number of items per page. It returns a new collection instance containing the items for the specified page. Alternatively, you can achieve similar results using the chunk method, which splits the collection into smaller collections, each containing a specified number of items. Accessing a specific page from the chunked collection can be done using the get method, passing the zero-based index of the desired page.
Laravel Collection Public API: get

Nov 29, 2016

The get method allows retrieving an item from a collection using a specific $key. If the $key does not exist, the method can return a default value or evaluate a callback to provide a fallback value. You can also use numeric keys to retrieve items from the collection.
Laravel Collection Public API: groupBy

Nov 29, 2016

The groupBy method is used to group a collection based on a given value. This value can be a string or a callback function. By default, the keys of the collection will not be preserved when grouping, but this can be changed by passing true as the second parameter. The method returns a new instance of the Collection class with the grouped items.
Laravel Collection Public API: has

Nov 29, 2016

The has method checks if an item exists in a collection based on a given key. It returns true if the item exists and false if it does not. Use it to easily determine item existence in a collection.
Laravel Collection Public API: implode

Nov 29, 2016

The implode method in Laravel's Collection class combines the items of the collection together, similar to PHP's [implode](http://php.net/manual/en/function.implode.php) function. It can be used on arrays of primitive data types as well as arrays of objects and arrays. In the code examples provided, the implode method is demonstrated to combine values with a delimiter, such as combining strings with a hyphen or names with a comma. It can be useful for creating messages for users, like displaying who has recently followed them on a micro-blogging platform.
Laravel Collection Public API: intersect

Nov 29, 2016

The intersect method in Laravel removes any values that are not in the provided array. It returns a new instance of the Collection class, preserving any original keys. An example usage of the intersect method is shown, demonstrating how it can filter the original collection based on the intersecting values from another array.
Laravel Collection Public API: isEmpty

Nov 29, 2016

Learn how to use the isEmpty method in Laravel's Collection class to check if a collection is empty or not. By using this method, true will be returned if the collection is empty, otherwise false.

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.