Use every() on Laravel Collections to verify whether every single item in a collection satisfies a truth test.
When validating whether all line items in an order are in stock, or confirming all members in a team have completed onboarding, looping and keeping boolean flags is error-prone.
The every() method evaluates a predicate callback across all items.
Basic Usage
$scores = collect([85, 92, 78, 90]);
// Returns true if all scores are >= 70
$allPassed = $scores->every(fn (int $score) => $score >= 70);
Checking Model Collections
$orderItems = $order->items;
// True only if every single item is in stock
$canFulfill = $orderItems->every(fn (OrderItem $item) => $item->quantity <= $item->product->stock);
Truthy Value Checks
If no callback is provided, every() checks if all elements are truthy:
$flags = collect([true, true, true]);
$allTrue = $flags->every(); // true
Summary
- Returns
trueif all items pass the condition; returnsfalseimmediately on the first failed item (short-circuiting). - Returns
trueon empty collections. - Replaces manual
foreachloops and state tracking flags.
Related Tips
View all tips →Simplify Collection Operations with Higher-Order Messages
Laravel Collections support higher-order messages through dynamic properties, allowing operations like each, map, filter, and groupBy to work directly with an item's property or method without writing boilerplate callbacks.
Generate Iterative Collections Quickly with Collection::times()
Use Collection::times() to generate numeric-sequence collections or execute closures N times fluently without writing for loops.