首页 > 解决方案 > 在 octobercms 中获取延迟保存的图像

问题描述

嗨,我在 octobercms 中使用“上传器”和 sitesearch 插件。使用上传器插件我在我的发布模型中保存多个图像后,它们显示在后端区域但没有检索。我以这种方式检索attachMany 关系发布图像,但是当我在content.htm文件中打印 {{result.model}} 时,它显示像这样的空数组

{"title":"gdsag","brandname":"Yamaha","description":"gdsga","price":5887,"name":"Rawalpindi","postingimage":[]}

无法在模型中获取延迟保存的图像 在站点搜索插件中获取这样的图像

if ($item->postingimage) {
                    return [
                        'title' => $item->title,
                        'text' => $item->description,
                        'text' => $item->price,
                        'text' => $item->brandname,
                        'text' => $item->name,
                        'thumb' => $item->postingimage->first(),

                        'relevance' => $relevance, // higher relevance results in a higher
                        'model' => $item, 
                    ];

我在组件中的 init 方法

public function init()
    {
        $component = $this->addComponent(
            'Responsiv\Uploader\Components\FileUploader',
            'fileUploader',
            ['deferredBinding' => true]
        );


        $component->bindModel('postingimage', new Posting);


    }

我在提交表单后以这种方式保存图像

 $posting->save(null, post('_session_key'));

有什么帮助吗?

标签: octobercms

解决方案


我得到了这个问题的解决方案

$matching = Posting::join('fsz_posting_tblbrands') // ... do your join

// Now refetch the needed models with all needed relations
$items = Posting::with('postingimage')->whereIn('id', $matching->pluck('id'))->get();

还要确保您的 $item 实际上是您的模型的一个实例,而不仅仅是一个集合。如果它是一个简单的集合,我们将无法加载关系


推荐阅读