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

m.saravanan
m.saravanan

public $attachOne = ['icon' => ['System\Models\File', 'order' => 'sort_order'],];

public function beforeSave() { $this->image = $this->icon->attributes['disk_name']; }


$this->image ========= image name like 1234567890.jpg image path will be ========= storage/app/uploads/public/123/456/789/1234567890.jpg


storage/app/uploads/public + image name first three char+'/'+ image name second three char+'/'+image name third three char+'/'+filename ========== image path

Last updated

maxDubovsky
maxDubovsky

Thanks for all your replyies, but I have found some issues that are not mentioned here. First of all you will get an error if you do not check for image existance:

public function getImageAttribute()
{
    $image = Company::find($this->id);
    if ($this->featured_image) {
        return '<img src="'.$image->featured_image->getThumb(50, 50, 'crop').'" />';
    }else{
        return '<img src="http://placehold.it/50x50" />';
    }
}

Second, you should specify the type of the field in the config_list.yaml

image:
    type: html
    label: Logo
    sortable: no

Otherwise you will get plain html there

Tschallacka
Tschallacka

Uhm... I just went for the simple solution by doing a partial?

featured_image:
    type: partial
    path: ~/controllers/something/partials/_displayimage.htm

and then in the partial

<?php foreach($value as $image) : ?>
       <img src="<?= $image->getThumb(50, 50, 'crop')" alt="<?= $image->title ?>">
<?php endforeach; ?>

The foreach will simply prevent non-existing images not to render.

Asinox
Asinox

Thank you @maxDubovsky, the fix for me was: type: html

Vijay Wilson
Vijay Wilson

Guys I have undergone all your works and did this, it just works fine

columns.yaml image: label: Logo / or any name you like which suits the field / type: html

In my model public $attachOne = ['logo'=>'System\Models\File'];

public function getImageAttribute()
{
    if($this->logo)
    {
        return '<img src="'.$this->logo->getThumb(50,50).'">';
    }
    else
    {
        return '<img  alt="No Logo" />';
    }
}
niquedegraaff25539
niquedegraaff25539

Not sure when this started to happen but this solution doesn't work anymore because October escapes HTML and litterally places the whole string.

Example image

Instead, add the column as a partial.

(i added this comment because this forum post is top ranked in Google, regarding this issue)

Last updated

LadyLain
LadyLain

Hi guys,

Thanks for all the answer you wrote. I just want to bring a solution to a bug not mentioned here.

<?php foreach($value as $image) : ?>
    <img src="<?= $image->getThumb(50, 50, 'crop') ?>" alt="<?= $image->title ?>">
<?php endforeach; ?>

So, when i was doing that partial to my attached file, it returned me an exception as "Call to a member function getThumb()".

I investigated it and found that the partial solution you wrote below works fine only if you use attackMany function.

If you have only one attach file, you'll need to have a partial like this

<img src="<?= $value->getThumb(50, 50, 'crop')?>" alt="<?= $value->title ?>"> 

Does that make sense ?

Best,

Last updated

maxDubovsky
maxDubovsky

$record->featured_image

cikyelderly
cikyelderly

Shahiem said: run 3

Like this?

(ShahiemSeymor\Forum\Models\Emoticons) public function getImageAttribute() { $image = Emoticon::find($this->id); return ''; }

You could use the getThumb() from the Database/Attach/File.php class?

info51276
info51276

seen that many had faced the issue - me too faced this and here is the solution for a single img upload.

  1. Write this in your model: public $attachOne = [ 'picture' => 'System\Models\File' ]; In columns.yaml image: label: Thumbnail type: partial path: {full_path}\partials_displayimage.htm In partials: <?= $record->title ?>

    And it works - hope it helps.

info51276
info51276
seen that many had faced the issue - me too faced this and here is the solution for a single img upload.
1. Write this in your model: 

public $attachOne = [
        'picture' => 'System\Models\File'
    ];

In columns.yaml
image:
        label: Thumbnail
        type: partial
        path: {full_path}\partials\_displayimage.htm
In partials:
<?= $record->title ?>
And it works - hope it helps.
jimlab56999
jimlab56999

Hi guys, I faced with the same issue, so as lack of documentation, share my solution.
1
in columns.yaml
columns:
estateimages: // important for this namespace
label: Image
type: partial
path: ~/plugins/eduard/estate/models/estate/_estateimages.htm
sortable: false
2
create _estateimages.htm inside your models folder (my case inside estate folder)
put this
<?=$value;
3
Put code in your models class (my case Estate.php)
public $attachMany = [
'images' => 'System\Models\File',
];

and:

public function getEstateimagesAttribute() //important to namespace! to step 1
{
foreach ($this->images as $image) {
return '<img src="'.$image->getThumb(110, 30, ['mode' => 'crop']).'" alt="" />';
}
}

Last updated

maxDubovsky
maxDubovsky

jimlab56999 partial should be within controller folder

21-33 of 33

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