My task is to display all contacts for selected groups. When i select two gorups like `facebook and instagram`, i have to display all contacts belonging to both group. 

When i select multiple groups like below and do `return $explode_groups`, i get the id's of both groups like `1,2`.

But my issue is, when i am displaying the contact as `return $selected_contacts` i get only contacts for group 1. 

Why is this happening?

**Group**

```
 public function customers()
    {
        return $this->belongsToMany('App\Customer','customer_group','group_id','customer_id')
        ->withTimestamps();
    }

```

**Customer**

```
 public function groups()
    {
        return $this->belongsToMany('App\Group','customer_group','customer_id','group_id')
        ->withTimestamps();
    }

```

**Controller**

```
$get_selected_groups = $request->get('group');

$explode_groups = implode(', ', $get_selected_groups);

$selected_groups = Group::where('id',$explode_groups)->first();

$selected_contacts = $selected_groups->customers()->get();

```

**response**

```
{"id":2,"title":"test","no_of_contacts":0,"user_id":1,"created_at":"2018-04-15 23:55:30","updated_at":"2018-04-15 23:55:30","customers":[{"id":1,"name":"Benson Jones Thomson","phone":"0247878234","group_id":null,"user_id":1,"created_at":"2018-04-16 00:14:20","updated_at":"2018-04-16 05:31:05","pivot":{"group_id":2,"customer_id":1,"created_at":"2018-04-16 05:33:08","updated_at":"2018-04-16 05:33:08"}},{"id":2,"name":"Lawrence Pitcher","phone":"0244371112","group_id":null,"user_id":1,"created_at":"2018-04-16 07:59:15","updated_at":"2018-04-16 07:59:15","pivot":{"group_id":2,"customer_id":2,"created_at":"2018-04-16 07:59:15","updated_at":"2018-04-16 07:59:15"}}]}

```