*/ protected $fillable = [ 'journal_id', 'slice_of_life_id', 'title', 'view_count', 'published', 'written_at', 'updated_at', ]; /** * The attributes that should be cast to native types. * * @var array */ protected $casts = [ 'published' => 'boolean', 'written_at' => 'datetime', 'updated_at' => 'datetime', ]; /** * Get the journal associated with the post. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo<\App\Models\Journal, $this> */ public function journal(): BelongsTo { return $this->belongsTo(Journal::class); } /** * Get the slice of life associated with the post. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo<\App\Models\SliceOfLife, $this> */ public function sliceOfLife(): BelongsTo { return $this->belongsTo(SliceOfLife::class); } /** * Get the post sections associated with the post. * * @return \Illuminate\Database\Eloquent\Relations\HasMany<\App\Models\PostSection, $this> */ public function postSections(): HasMany { return $this->hasMany(PostSection::class); } /** * Get the contacts associated with the post. * * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany<\App\Models\Contact, $this> */ public function contacts(): BelongsToMany { return $this->belongsToMany(Contact::class); } /** * Get the post's feed item. * * @return \Illuminate\Database\Eloquent\Relations\MorphOne<\App\Models\ContactFeedItem, $this> */ public function feedItem(): MorphOne { return $this->morphOne(ContactFeedItem::class, 'feedable'); } /** * Get the tags associated with the post. * * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany<\App\Models\Tag, $this> */ public function tags(): BelongsToMany { return $this->belongsToMany(Tag::class); } /** * Get the files associated with the post. * * @return \Illuminate\Database\Eloquent\Relations\MorphMany<\App\Models\File, $this> */ public function files(): MorphMany { return $this->morphMany(File::class, 'fileable'); } /** * Get the post metrics associated with the post. * * @return \Illuminate\Database\Eloquent\Relations\HasMany<\App\Models\PostMetric, $this> */ public function postMetrics(): HasMany { return $this->hasMany(PostMetric::class); } /** * Get the post's title. * * @return Attribute */ protected function title(): Attribute { return Attribute::make( get: function ($value) { if ($value) { return $value; } return trans('Undefined'); }, set: fn ($value) => $value, ); } /** * Get the post's body excerpt. * * @return Attribute */ protected function excerpt(): Attribute { return Attribute::make( get: fn () => Str::limit(optional($this->postSections()->whereNotNull('content')->first())->content, 200) ); } }