From 367d27258c501f32aa68b26108ac1b24639a4494 Mon Sep 17 00:00:00 2001 From: karneaud Date: Mon, 15 Jul 2024 15:07:27 -0400 Subject: [PATCH] add company id to array --- .../Transformer/Quickbooks/ClientTransformer.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/app/Import/Transformer/Quickbooks/ClientTransformer.php b/app/Import/Transformer/Quickbooks/ClientTransformer.php index c70ced06e9..3134763078 100644 --- a/app/Import/Transformer/Quickbooks/ClientTransformer.php +++ b/app/Import/Transformer/Quickbooks/ClientTransformer.php @@ -58,9 +58,9 @@ class ClientTransformer extends BaseTransformer $transformed_data[$key] = method_exists($this, $method = sprintf("get%s", str_replace(".","",$field)) )? call_user_func([$this, $method],$data,$field) : $this->getString($data, $field); } - $transformed_data = (new Model)->fillable(array_keys($this->fillable))->fill($transformed_data)->toArray() + $this->getContacts($data, $field); - - return $transformed_data; + $transformed_data = (new Model)->fillable(array_keys($this->fillable))->fill($transformed_data); + $transformed_data->contacts[0] = $this->getContacts($data)->toArray()+['company_id' => $this->company->id ]; + return $transformed_data->toArray() + ['company_id' => $this->company->id ] ; } public function getString($data, $field) @@ -68,15 +68,14 @@ class ClientTransformer extends BaseTransformer return Arr::get($data, $field); } - protected function getContacts($data, $field = null) { - return [ 'contacts' => [ - (new ClientContact())->fill([ + protected function getContacts($data) { + return (new ClientContact())->fill([ 'first_name' => $this->getString($data, 'GivenName'), 'last_name' => $this->getString($data, 'FamilyName'), 'phone' => $this->getString($data, 'PrimaryPhone.FreeFormNumber'), 'email' => $this->getString($data, 'PrimaryEmailAddr.Address'), - ]) ] - ]; + 'company_id' => $this->company->id + ]); }