From e769e3d2d37f2cd3e812441da4744e60fdd6b5bd Mon Sep 17 00:00:00 2001 From: Ash Allen Date: Wed, 21 Apr 2021 14:12:57 +0100 Subject: [PATCH] [9.x] Add sole() to Enumerable contract. (#37066) * Added sole() to Enumerable contract. * Update Enumerable.php Co-authored-by: Taylor Otwell --- src/Illuminate/Collections/Enumerable.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Illuminate/Collections/Enumerable.php b/src/Illuminate/Collections/Enumerable.php index 4bda35476905..29b123d53525 100644 --- a/src/Illuminate/Collections/Enumerable.php +++ b/src/Illuminate/Collections/Enumerable.php @@ -808,6 +808,19 @@ public function slice($offset, $length = null); */ public function split($numberOfGroups); + /** + * Get the first item in the collection, but only if exactly one item exists. Otherwise, throw an exception. + * + * @param mixed $key + * @param mixed $operator + * @param mixed $value + * @return mixed + * + * @throws \Illuminate\Collections\ItemNotFoundException + * @throws \Illuminate\Collections\MultipleItemsFoundException + */ + public function sole($key = null, $operator = null, $value = null); + /** * Chunk the collection into chunks of the given size. *