Expanding featured_image for multiples

Laraship QuestionsCategory: TechnicalExpanding featured_image for multiples
duncan asked 6 years ago

Hi,

I need to expand the featured_image on the homepage to allow 12 images, I have them adding to the database on update and appearing on the views within CMS, but I'm struggling to pull them into the edit page of the CMS.

I can’t figure out is where $page->featured_image is being set for use on create_edit.blade.php within ‘CMS/resources/views/pages/‘. If I dump($page->featured_image) it returns the correct entry from the media table for collection name 'featured_image', however I have set a new collection_name to ‘featured_image1,2,3,4’ etc but can’t see how to populate $page->featured_image1,2,3,4 etc.

When I dump ($page) there are no attributes for ‘featured_image’, yet it’s magically there if you dump $page->featured_image.

Any help appreciated.

1 Answers
Best Answer
laraship Staff answered 6 years ago

Hello,

Featured image is set at Corals/modules/CMS/Models/Content.php

    public function getFeaturedImageAttribute()

{

$media = $this->getFirstMedia('featured-image');

if ($media) {

return $media->getUrl();

} elseif (isset($this->attributes['featured_image_link']) && $this->attributes['featured_image_link']) {

return url($this->attributes['featured_image_link']);

}

return null;

}

duncan replied 6 years ago

Thank you.