Skip to content

Commit

Permalink
collection stay in the memory for every request
Browse files Browse the repository at this point in the history
static::$kabsaCollection will save the collection in the memory so no need to call getRows every time
  • Loading branch information
BSN4 authored Mar 29, 2020
1 parent ade55e1 commit ecf6d8b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Traits/Kabsa.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@

trait Kabsa
{
static $kabsaCollection;

public function getRows()
{
return $this->rows;
}

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)
Expand Down

0 comments on commit ecf6d8b

Please sign in to comment.