I have group and group members one table is for group where i am storing just group name and second table is group members where i have user\_id,group\_id field.

I am creating API using postman and i want to insert group members details like this:

`"group_members": [1,3]`

My body request is:

```
{
    "name": "Steve", // name is group name
    "group_members": [1,3]  // [1,3] here 1 and 3 is user_id
}

```

I want to store [1,3] into group\_members table in user\_id field against group\_id if there is [1,3] then two entries should be enter in user\_id field
i have also attached the screen shot of my table:

My Controller:

```
DB::beginTransaction();

    try{

        $request->request->add(['created_by' => Auth::user()->id]);
        $group = $this->group->create($request->only($this->group->getModel()->fillable));
        $request->request->add(['group_id' => $group->id]);
        $this->groupMembers->create($request->only($this->groupMembers->getModel()->fillable));

        DB::commit();

        return response([
            'status' => true,
            'message' => 'Group added',

        ], 200);

    } catch(\Exception $ex) {
        DB::rollback();
        return response([
            'status' => false,
            'message' => __('messages.validation_errors'),
            'errors' => $ex->getMessage(),
        ], 500);
    }

```

How i can store this array values into database your help will be highly appreciated?[![enter image description here](https://i.stack.imgur.com/dpQxm.png)](https://i.stack.imgur.com/dpQxm.png)

```
               try {

        $group = $this->group->find($request->input('id'));
        $request->request->add(['updated_by' => Auth::user()->id]);
        $group->fill($request->all())->save();

        return response(['status' => true, 'message' => 'Group updated'], 500);

    } catch (\Exception $ex) {
        return response(['status' => false, 'message' => 'Validation Errors', 'errors' => $ex->getMessage()], 500);
    }

      public function updateGroup(Request $request)
    {
    $validator = UserValidations::validateGroup($request->all());

    if($validator->fails()) {
        return response(['status' => false, 'message' => 'Validation Errors', 'errors' => $validator->errors()->all()], 500);
    }

    try {

        $group = $this->group->find($request->input('id'));
        $request->request->add(['updated_by' => Auth::user()->id]);
        $group->fill($request->all())->save();

        return response(['status' => true, 'message' => 'Group updated'], 500);

    } catch (\Exception $ex) {
        return response(['status' => false, 'message' => 'Validation Errors', 'errors' => $ex->getMessage()], 500);
    }
}

```