This query returns all groups with an id however it also returns all the products to every group.
$groups = \App\Group::where('campaign_id', $id)->with('product')->get();
dd($groups->toArray());array:2 [▼
This is the output.
0 => array:6 [▼
"id" => 24
"campaign_id" => "TRE36934"
"group_name" => "group2"
"created_at" => "2017-05-17 16:14:55"
"updated_at" => null
"product" => array:4 [▼
0 => array:8 [▶]
1 => array:8 [▶]
2 => array:8 [▶]
3 => array:8 [▶]
I am trying to return the groups with same id. Can I somehow query? The join in the id in the groups table and the foreign key in call 'group' in the group table.