Reputation: 1272
I’m trying to make a dynamic resume. To show the skills I’ve created 3 tables as follows-
Skills
Groups
Skill_Groups
Now, I would like to display the groups and skills with nested list. Example-
Front end
⁃ HTML
⁃ CSS
Back End
⁃ PHP
⁃ MySQL
For this, I need a multidimensional array. What should be the query in laravel to get the result on this way?
[This question may be duplicate one, but I didn’t found. If so, please let me know, I will merge/delete it.]
Any alternate solutions also appreciable, if have.
Upvotes: 2
Views: 906
Reputation: 1835
In Model Group
you can add relationship
public function skills()
{
return $this->belongsToMany(Skill::class, 'skill_groups');
}
In Controller
$groups = Group::with('skills')->get();
In View
@foreach($groups as $group)
{{ $group->name }}
@foreach($group->skills as $skill)
{{ $skill->name }}
@endforeach
@endforeach
Upvotes: 2