status == self::STATUS_DRAFT; } /** * Is current content visible for all visitors? * * @return bool */ public function isPublic() { return $this->status == self::STATUS_PUBLIC; } /** * Is current content visible only for logged users? * * @return bool */ public function isProtected() { return $this->status == self::STATUS_PROTECTED; } /** * Is current content visible for logged user OR for everyone? * * @return bool */ public function isVisible() { return $this->isPublic() || $this->isProtected(); } /** * Mark relationship with its historical records * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function history() { return $this->hasMany(\App\Models\Content\ContentHistory::class); } /** * Mark relationship with users table * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function author() { return $this->belongsTo(User::class, 'user_id'); } /** * 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); } public function save(array $options = []) { $saved = parent::save($options); // fire event about creating new content page if ($this->wasRecentlyCreated) { Event::fire(new CreateNewContent($this)); } return $saved; } }