'boolean', 'moduleSettings' => 'array' ]; /** * Assign observer for this model for logging */ protected static function boot() { parent::boot(); self::observe(ContentObserver::class); } /** * Mark relationship with its historical records * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function history() { return $this->hasMany(ContentHistory::class); } /** * Mark relationship with users table * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function author() { return $this->belongsTo(User::class, 'userId'); } /** * Related files to content page * * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ public function files() { return $this->belongsToMany(File::class, 'contents_has_files'); } /** * Category of content page * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function category() { return $this->belongsTo(Category::class); } /** * Subpages assigned to page * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function subpages() { return $this->hasMany(Content::class, 'parentId'); } /** * Parent page * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function parentPage() { return $this->belongsTo(Content::class, 'parentId'); } /** * Is current content draft? * * @return bool */ public function isDraft() { return $this->status == ContentContract::STATUS_DRAFT; } /** * Is current content visible for all visitors? * * @return bool */ public function isPublic() { return $this->status == ContentContract::STATUS_PUBLIC; } /** * Is current content visible only for logged users? * * @return bool */ public function isProtected() { return $this->status == ContentContract::STATUS_PROTECTED; } /** * Is current content visible for logged user OR for everyone? * * @return bool */ public function isVisible() { return $this->isPublic() || $this->isProtected(); } public function save(array $options = []) { $this->parentId = $this->nullable($this->parentId); $this->categoryId = $this->nullable($this->categoryId); $this->publishedFrom = $this->nullableDate($this->publishedFrom); $this->publishedTo = $this->nullableDate($this->publishedTo); $this->url = Str::slug($this->url); return parent::save($options); } }