How to avoid double foreach in backward relationships in Laravel?
تبليغيرجى شرح بإيجاز لمإذا تشعر أنك ينبغي الإبلاغ عن هذا السؤال.
I am trying to print some variables with these relations:
The first:
return $this->belongsTo(Group::class);
}
The second:
return $this->hasMany(JoinGroup::class);
}
My question is how could I access $group->joinGroups->name_group without doing a double foreach? I must do this that I show you below because the relationships are upside down…
@foreach($group->joinGroups as $joinGroups)
{{$joinGroups->name_group}}
@endforeach
@endforeach
Is there an easier way to avoid the middle foreach? According to what code everything is duplicated.
أضف إجابة