From ecf6d8b55e2dc16d6d8d610602dd7a5c21b76db2 Mon Sep 17 00:00:00 2001 From: Bader Almutairi Date: Mon, 30 Mar 2020 00:30:58 +0300 Subject: [PATCH] collection stay in the memory for every request static::$kabsaCollection will save the collection in the memory so no need to call getRows every time --- src/Traits/Kabsa.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Traits/Kabsa.php b/src/Traits/Kabsa.php index f7d0ddd..44e2fe5 100755 --- a/src/Traits/Kabsa.php +++ b/src/Traits/Kabsa.php @@ -7,6 +7,8 @@ trait Kabsa { + static $kabsaCollection; + public function getRows() { return $this->rows; @@ -14,10 +16,14 @@ public function getRows() public static function all($columns = []) { + if(!empty(static::$kabsaCollection)) { + return static::$kabsaCollection; + } + self::unguard(); $self = new self(); - return Collection::make($self->getRows() ?? [])->map(function ($row) { return new self($row); }); + return static::$kabsaCollection = Collection::make($self->getRows() ?? [])->map(function ($row) { return new self($row); }); } public function __call($method, $parameters)