我使用hasMany和belongsTo创建了我的模型图像和相册之间的前端关系但是我没有显示任何结果和
{{ dump(images) }}
和{{ dump(albums) }}
提供Object variables NULL 0 NULL
为什么没有接受这种关系的任何想法?
相册
public $hasMany = [
'images' => [ 'Acme\Library\Models\Image' ,'key'=>'album_id'],
];
图像
public $belongsTo = [
'albums' => ['Acme\Library\Models\Album']
];
专辑-details.htm
{{ dump(images) }}
{% for image in images %}
{{image.id|raw }}
{% endfor %}
如果我在{{ dump(record) }}
上运行转储,我会
Object variables
Acme\Library\Models\Album
bootValidation() method Boot the validation trait for this model.
forceSave() method Force save the model even if validation fails.
validate() method Validate the model instance
isAttributeRequired() method Determines if an attribute is required based on the validation rules.
errors() method Get validation error message collection for the Model
validating() method Create a new native event for handling beforeValidate().
validated() method Create a new native event for handling afterValidate().
rules array(0)
timestamps boolean
table string
relationConfig string
hasMany array(1)
我可以看到使用构建器插件定义了记录{% set records = builderList.records %}
是否需要以这种方式定义专辑/图像?
答案 0 :(得分:1)
我将记录变量发送到视图,记录是相册的一个实例,您可以通过这种方式访问图像。
{% for image in record.images %}
{{image.id|raw }}
{% endfor %}