From b496d47d347619ba8e6a41b59cc91a12d6614946 Mon Sep 17 00:00:00 2001 From: Awilum Date: Wed, 15 Jul 2020 23:39:28 +0300 Subject: [PATCH] feat(element-queries): update methods first() next() last() #436 --- src/flextype/Support/Collection.php | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/flextype/Support/Collection.php b/src/flextype/Support/Collection.php index f981e2e2..55d0ae00 100644 --- a/src/flextype/Support/Collection.php +++ b/src/flextype/Support/Collection.php @@ -298,7 +298,17 @@ class Collection */ public function last() : array { - return array_undot($this->matchCollection()->last()); + // Match collection + $collection = $this->collection->matching($this->criteria); + + // Restore error_reporting + error_reporting($this->errorReporting); + + // Gets first matching result + $results = $collection->last(); + + // Return first matching result + return is_array ($results) ? array_undot($results) : $results; } /** @@ -312,7 +322,17 @@ class Collection */ public function next() : array { - return array_undot($this->matchCollection()->next()); + // Match collection + $collection = $this->collection->matching($this->criteria); + + // Restore error_reporting + error_reporting($this->errorReporting); + + // Gets first matching result + $results = $collection->next(); + + // Return first matching result + return is_array ($results) ? array_undot($results) : $results; } /** @@ -361,8 +381,11 @@ class Collection // Restore error_reporting error_reporting($this->errorReporting); + // Gets first matching result + $results = $collection->first(); + // Return first matching result - return $collection->first(); + return is_array ($results) ? array_undot($results) : $results; } /**