From 252c6f0a564d08bb3c658ff210db6d144f20a5a4 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Mon, 7 Aug 2017 14:04:33 +0300 Subject: [PATCH] Prevent creating clients without contacts --- app/Models/Client.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Models/Client.php b/app/Models/Client.php index f5c8be3d8f..4a6d8486e6 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -244,7 +244,9 @@ class Client extends EntityModel { $publicId = isset($data['public_id']) ? $data['public_id'] : (isset($data['id']) ? $data['id'] : false); - if ($publicId && $publicId != '-1') { + // check if this client wasRecentlyCreated to ensure a new contact is + // always created even if the request includes a contact id + if (! $this->wasRecentlyCreated && $publicId && $publicId != '-1') { $contact = Contact::scope($publicId)->firstOrFail(); } else { $contact = Contact::createNew();