octobercms - 在 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'));
有什么帮助吗?
解决方案
我得到了这个问题的解决方案
$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 实际上是您的模型的一个实例,而不仅仅是一个集合。如果它是一个简单的集合,我们将无法加载关系
推荐阅读
- oracle - 如何修复此 Sql 代码以在 KEEN 教授的课程中给出学生的姓名及其成绩比灰色的最高成绩更好的成绩
- javascript - 如何使用 tensorflow.js 创建参差不齐的张量
- jquery - Jquery在新行中返回数字
- r - 按一列分组并查看另一列不均匀长度的所有唯一结果
- c++ - 使用指针新建和删除
- php - 我如何删除php中的孔行?
- java - 如何使用“org.apache.commons.net.ftp.FTPClient”解决异常
- android - 应用程序启动Android应用程序后,如何为用户订阅通知主题?
- python - 如何使用 pandas Series.interpolate 将数据插入 NAN
- laravel - SMTP:从 Laravel 5.7 (Swift Mailer) 发送电子邮件时更改 Message-ID 域