From d90ca08ba674b81f7d70ab5c224f63a9947325f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kv=C3=A1=C4=8Dek?= Date: Fri, 8 Sep 2017 00:33:46 +0200 Subject: [PATCH] FEATURE: add new relationship to Content model - only visible subpages --- app/Models/Content/Content.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/Models/Content/Content.php b/app/Models/Content/Content.php index de8a9c35..6901c023 100644 --- a/app/Models/Content/Content.php +++ b/app/Models/Content/Content.php @@ -103,6 +103,23 @@ class Content extends Model return $this->hasMany(Content::class, 'parentId'); } + /** + * Subpages assigned to page + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function publishedSubpages() + { + $query = $this->hasMany(Content::class, 'parentId'); + + if (\Auth::check()) { + $query = $query->where('status', '!=', ContentContract::STATUS_DRAFT); + } else { + $query = $query->where('status', ContentContract::STATUS_PUBLIC); + } + + return $query; + } + /** * Module relationship * @return \Illuminate\Database\Eloquent\Relations\BelongsTo