This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hello,
I built a plugin with 2 models : Operation and Category, with a Many to Many relationship, something classic :
public $belongsToMany = [
'categories' => [
'Me\MyPlugin\Models\Category',
'table' => 'me_myplugin_operations_categories',
'key' => 'operation_id',
'otherKey' => 'category_id'
]
];
I also setup the inverse relation.
The category model have some image attached to it like that :
public $attachMany = [
'images' => 'System\Models\File'
];
I use the default Builder plugin component to list my operations. I want to display the first category image next to the operation, here is my code :
{% for operation in builderList.records %}
{{ d(operation.categories) }}
Image path : {{ operation.categories.images.first.path }}
Operation title : {{ operation.title }}
{% endfor %}
I don't understand why I cannot display the first image path, I believe I setup the relation correctly, my dump of operation.categories correctly display the category collection.
Do I miss somehting ?
Thanks
My bad, I just saw that I need to loop into my categories to as it's a many to many relation.
So like that, it works : {{ operation.categories.first.images.first.path }}
^^
1-2 of 2