From ce030a40d4a3cd9ac64fe39d345e5668af8c238a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kv=C3=A1=C4=8Dek?= Date: Sat, 2 Apr 2016 19:11:46 +0200 Subject: [PATCH] FEATURE: cache results for Content::subpages() --- app/Models/Content.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/Models/Content.php b/app/Models/Content.php index ee83c568..300d1eec 100644 --- a/app/Models/Content.php +++ b/app/Models/Content.php @@ -30,6 +30,8 @@ class Content extends Model 'status' ]; protected $guarded = []; + protected $subpages = []; + protected $subpagesInit = false; const STATUS_DELETED = 'deleted'; const STATUS_DRAFT = 'draft'; const STATUS_PROTECTED = 'protected'; @@ -76,9 +78,14 @@ class Content extends Model */ public function subpages() { - return $this->getPageQuery() - ->where('parent_id', $this->id) - ->get(); + if (!$this->subpagesInit) { + $this->subpages = $this->getPageQuery() + ->where('parent_id', $this->id) + ->get(); + $this->subpagesInit = true; + } + + return $this->subpages; } /**