$gallery * @property-read int|null $gallery_count * @method static Builder|News inQueue(int $daysRejected = 7) * @method static Builder|News newModelQuery() * @method static Builder|News newQuery() * @method static Builder|News onlyTrashed() * @method static Builder|News published() * @method static Builder|News query() * @method static Builder|News whereCategoryId($value) * @method static Builder|News whereCommentsThreadId($value) * @method static Builder|News whereCreatedAt($value) * @method static Builder|News whereDeletedAt($value) * @method static Builder|News whereDescription($value) * @method static Builder|News whereEntryId($value) * @method static Builder|News whereId($value) * @method static Builder|News whereRejectedAt($value) * @method static Builder|News whereRelevantLink($value) * @method static Builder|News whereSlug($value) * @method static Builder|News whereStaffComment($value) * @method static Builder|News whereState($value) * @method static Builder|News whereTitle($value) * @method static Builder|News whereUpdatedAt($value) * @method static Builder|News whereUserId($value) * @method static Builder|News whereYoutubeLink($value) * @method static Builder|News withTrashed(bool $withTrashed = true) * @method static Builder|News withoutTrashed() * @mixin \Eloquent */ class News extends Model { use SoftDeletes, HasGallery, HasXenforoUserId, LogsActivity; protected $table = 'news'; protected $fillable = [ 'title', 'slug', 'description', 'state', 'category_id', 'entry_id', 'relevant_link', 'youtube_link', 'user_id', 'comments_thread_id', 'staff_comment', 'rejected_at', 'created_at' ]; protected $casts = [ 'rejected_at' => 'datetime', ]; public function scopePublished(Builder $query): Builder { return $query->where('state', 'published' ); } public function scopeInQueue( Builder $query, int $daysRejected = 7 ): Builder { return $query->withTrashed()->where(function($q) use($daysRejected) { $q->where('state', 'pending')->whereNull('deleted_at'); })->orWhere(function($q) use($daysRejected) { $q->where('state', 'rejected')->whereNotNull('rejected_at')->where('rejected_at', '>=', now()->subDays($daysRejected) ); }); } public function entry(): BelongsTo { return $this->belongsTo(Entry::class); } public function category(): BelongsTo { return $this->belongsTo(Category::class); } public function getDescriptionHtmlAttribute(): string { $converter = new GithubFlavoredMarkdownConverter([ 'html_input' => 'strip', 'allow_unsafe_links' => false, ]); return $converter->convert($this->description)->getContent(); } public function getYoutubeVideoId(): ?string { if( !$this->youtube_link ) return null; return EntryHelpers::getYoutubeVideoId( $this->youtube_link ); } public function getActivitylogOptions(): LogOptions { return LogOptions::defaults() ->useLogName('news') ->logAll() ->logOnlyDirty() ->dontLogEmptyChanges() ->setDescriptionForEvent(fn(string $eventName) => "News {$eventName}"); } }