Reputation: 852
In Model, when I have a hasMany relation, can I somehow get the values of a certain attribute concatenated? Is there something like that?
public function getRelatedManyAttribute() {
return $this->relatedMany->concat('attributeMany');
}
Upvotes: 1
Views: 1557
Reputation: 1296
I am not entirely sure if I understood you cerrectly, but if you want all the values of the same attribute of a 1:n-relation it could be this simple oneliner:
public function getIdsConcatenated() {
return implode(', ', ArrayHelper::getColumn($this->myManyRelation, 'id'));
}
Upvotes: 1
Reputation: 139
I think you are looking for this -
public function getSubMenuMenu()
{
return $this->hasMany(Your_table_name::className(), ['id' => 'your_column_name']);;
}
for more understanding visit this link
Upvotes: 0