hasMany(Post::class); } public function coverMedia(): BelongsTo { return $this->belongsTo(MediaLibrary::class, 'cover_media_id'); } public function coverImageUrl(): ?string { $libraryUrl = $this->coverMedia?->url; if (filled($libraryUrl)) { return (string) $libraryUrl; } return $this->getFirstMedia('cover')?->getUrl(); } public function getUrlAttribute(): string { return route('category.show', $this->id); } public function registerMediaCollections(): void { $this->addMediaCollection('cover') ->useDisk(\App\Support\MediaDisk::name()) ->singleFile(); } }