[ Attachment::class, 'post_id' ] ]; public $belongsTo = [ 'page' => [ Page::class, 'page_id' ] ]; public $belongsToMany = []; public $morphTo = []; public $morphOne = []; public $morphMany = []; public $attachOne = []; public $attachMany = []; public function beforeDelete() { $this->attachments->each->delete(); } // ---------------------------------- Getters ---------------------------------- // ***************************************************************************** public function getFeaturedImageAttribute(): ?string { return optional($this->attachments->first())->href; } // ---------------------------------- Scopes ----------------------------------- // ***************************************************************************** public function scopeWithIntro(Builder $q): Builder { return $q->selectSub('SELECT SUBSTRING(message, 1, 200)', 'intro'); } }