From f5d4ec951e136af3656988a7a08f4b6f508a56f5 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 2 Oct 2019 17:52:38 +1000 Subject: [PATCH] fixes for client creation --- app/Repositories/ClientContactRepository.php | 21 ++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/app/Repositories/ClientContactRepository.php b/app/Repositories/ClientContactRepository.php index 9f437c2d66cb..787ebff73029 100644 --- a/app/Repositories/ClientContactRepository.php +++ b/app/Repositories/ClientContactRepository.php @@ -45,15 +45,20 @@ class ClientContactRepository extends BaseRepository //loop and update/create contacts $contacts->each(function ($contact) use ($client){ + + $update_contact = null; - $update_contact = ClientContact::firstOrNew( - ['id' => $contact['id']], - [ - 'client_id' => $client->id, - 'company_id' => $client->company_id, - 'user_id' => auth()->user()->id - ] - ); + if(isset($contact['id'])) + $update_contact = ClientContact::find($this->decodePrimaryKey($contact['id'])); + + if(!$update_contact){ + + $update_contact = new ClientContact; + $update_contact->client_id = $client->id; + $update_contact->company_id = $client->company_id; + $update_contact->user_id = $client->user_id; + + } $update_contact->fill($contact);