This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

chris10207
chris10207

Hi guys, did anyone find a way to render a image in a column for a backend list ? i just need to show a logo for a brand listing. thanks

chris10207
chris10207

one solution would be : in the model, create a attribute getter like

public function getImgLogoAttribute()
    {
        if ($this->logo) {
            return $this->logo->getPath();
        } else 
{}
    }

in the columns.yaml of the same model

imglogo:
        label: smartbuild.asia::lang.brand.logo
        searchable: false
        type: partial
        path: img_logo

and finally, create a partial file in the controller folder of handling the model, like _img_logo.htm


Last updated

chris10207
chris10207

and finally, create a partial file in the controller folder which handle the model, like _img_logo.htm to render the html for the img based on the var record->ImgLogo

kubis
kubis

I combine all together

in model put this function public function getImageAttribute() { $project = $this->find($this->id);

if ($project->logo) {
       return $project->logo;
} 
}

or if we have attachMany relation public $attachMany = [ 'pictures' => 'System\Models\File' ]; then


public function getImageAttribute() { $project = $this->find($this->id);

    if ($project->pictures[0]) { 
        return $project->pictures[0];
    } 
}

and finally, create a partial file in the controller folder which handle the model, like _img_logo.htm to render the html for the img based on the var record->image in partial file (_img_logo.htm) write ''

Last updated

1-4 of 4

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.