public function updateCustomRecord($parameters) { Form::where('id_401', $parameters['id'])->update(['name_401' => $this->request->input('name'), 'email_account_id_401' => $this->request->input('emailAccount'), 'push_notification_401' => $this->request->has('pushNotification')]); $forwardsData = json_decode($this->request->input('forwardsData')); $ids = []; foreach ($forwardsData as $forwardData) { if (isset($forwardData->id_402)) { $ids[] = $forwardData->id_402; Forward::where('id_402', $forwardData->id_402)->update(["name_402" => $forwardData->name_402, "email_402" => trim(strtolower($forwardData->email_402)), "comments_402" => $forwardData->comments_402, "states_402" => $forwardData->states_402]); } else { $forwards[] = ["form_id_402" => $parameters['id'], "name_402" => $forwardData->name_402, "email_402" => trim(strtolower($forwardData->email_402)), "comments_402" => $forwardData->comments_402, "states_402" => $forwardData->states_402]; } } if (count($ids) > 0) { // to delete forwards the we have delete Forward::whereNotIn('id_402', $ids)->delete(); } if (isset($forwards) && count($forwards) > 0) { Forward::insert($forwards); } }