parseCustomFields($data['custom_fields']); } $company->fill($data); // nlog($data); /** Only required to handle v4 migration workloads */ if(Ninja::isHosted() && $company->isDirty('is_disabled') && !$company->is_disabled) { Ninja::triggerForwarding($company->company_key, $company->owner()->email); } if (array_key_exists('settings', $data)) { $company->saveSettings($data['settings'], $company); } if(isset($data['smtp_username'])) { $company->smtp_username = $data['smtp_username']; } if(isset($data['smtp_password'])) { $company->smtp_password = $data['smtp_password']; } if(isset($data['e_invoice']) && is_array($data['e_invoice'])){ //ensure it is normalized first! $data['e_invoice'] = $this->arrayFilterRecursive($data['e_invoice']); $company->e_invoice = $data['e_invoice']; } $company->save(); return $company; } private function arrayFilterRecursive(array $array): array { foreach ($array as $key => $value) { if (is_array($value)) { // Recursively filter the nested array $array[$key] = $this->arrayFilterRecursive($value); } // Remove null values if (is_null($array[$key])) { unset($array[$key]); } } return $array; } /** * parseCustomFields * * @param array $fields * @return array */ private function parseCustomFields($fields): array { foreach ($fields as &$value) { $value = (string) $value; } return $fields; } }