十月cms文件附件只有路径?

时间:2019-08-19 05:29:14

标签: laravel octobercms octobercms-backend

我是十月份的CMS新用户。现在我有文件附件问题。在模型中:

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

现在在控制器中:

$comic = Comic::with('cover_image)->find($id);

返回:

{
"id": 24,
"title": "Comic example detail",
"description": "Comic example detail",
"total_page": "14",
"cover_image": {
"id": 165,
"disk_name": "5d5a21ca68bf9280597931.png",
"file_name": "img06.png",
"file_size": 142958,
"content_type": "image/png",
"title": null,
"description": null,
"field": "cover_image",
"sort_order": 165,
"created_at": "2019-08-19 04:12:58",
"updated_at": "2019-08-19 04:15:23",
"path": "http://localhost:10080/storage/app/uploads/public/5d5/a21/ca6/5d5a21ca68bf9280597931.png",
"extension": "png"
}
} 

我希望Cover_image仅返回某些字段,如下所示:

"cover_image": {
"id": 165,
"file_name": "img06.png",
"path": "http://localhost:10080/storage/app/uploads/public/5d5/a21/ca6/5d5a21ca68bf9280597931.png",
}

我该怎么办?

1 个答案:

答案 0 :(得分:0)

使用约束优先加载

请参见文档https://octobercms.com/docs/database/relations#constraining-eager-loads

使用where语句进行了解释,但是您可以使用select语句,并且只能获得必需的attributes

我相信它将为您提供帮助。

相关问题