partition() splits a collection into two groups in one pass. sole() asserts there's exactly one match and hands it to you directly. Both quietly replace common loop patterns.
#Collections
Articles
When a dataset is too large to hold in memory as a Collection, LazyCollection processes it one item at a time using generators.
Two small Laravel features, the tap() helper and higher-order collection messages, quietly remove a surprising amount of boilerplate from everyday code.
Eight practical Laravel patterns that make your code read more like intent and less like implementation — from fluent helpers to conditional chains.
Most foreach loops in a Laravel app can be replaced with a single, more readable collection method. Here are seven that will clean up your code today.