$reactions * @property-read Collection $comments * @property-read Collection $tags * * @method static \Illuminate\Database\Eloquent\Builder|WebsiteArticle where($column, $operator = null, $value = null) * @method static \Illuminate\Database\Eloquent\Builder|WebsiteArticle whereNot($column, $operator = null, $value = null) * @method static \Illuminate\Database\Eloquent\Builder|WebsiteArticle whereHas($relation, \Closure $callback = null, $operator = '>=', $count = 1) * @method static \Illuminate\Database\Eloquent\Builder|WebsiteArticle latest($column = 'created_at') * @method static \Illuminate\Database\Eloquent\Builder|WebsiteArticle get($columns = ['*']) * @method static \Illuminate\Database\Eloquent\Builder|WebsiteArticle take(int $value) * @method static \Illuminate\Database\Eloquent\Builder|WebsiteArticle with($relations) * @method static \Illuminate\Database\Eloquent\Builder|WebsiteArticle has($relation, \Closure $callback = null, $operator = '>=', $count = 1) */ class WebsiteArticle extends Model { use BelongsToUser; use HasSlug, \Illuminate\Database\Eloquent\Factories\HasFactory, SoftDeletes; /** @var array */ #[\Override] protected $with = ['user']; protected static function newFactory() { return WebsiteArticleFactory::new(); } #[\Override] protected $guarded = ['id', 'created_at', 'updated_at', 'user_id', 'slug', 'visible', 'fixed']; public function getSlugOptions(): SlugOptions { return SlugOptions::create() ->generateSlugsFrom('title') ->saveSlugsTo('slug') ->usingSeparator('-')->allowDuplicateSlugs(); } public function reactions(): HasMany { return $this->hasMany(WebsiteArticleReaction::class, 'article_id') ->whereActive(true); } public function comments(): HasMany { return $this->hasMany(WebsiteArticleComment::class, 'article_id'); } public function userHasReachedArticleCommentLimit(): bool { return $this->comments()->where('user_id', '=', Auth::id())->count() >= (int) setting('max_comment_per_article'); } #[\Override] protected static function boot() { parent::boot(); static::saving(function ($model) { if (empty($model->image)) { $model->image = ''; } }); } public function tags() { return $this->morphToMany(Tag::class, 'taggable'); } }