diff --git a/app/Models/Client.php b/app/Models/Client.php index de128945adb3..24b45e131fc2 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -262,7 +262,7 @@ class Client extends EntityModel // 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(); + $contact = Contact::scope($publicId)->whereClientId($this->id)->firstOrFail(); } else { $contact = Contact::createNew(); $contact->send_invoice = true; diff --git a/app/Models/Vendor.php b/app/Models/Vendor.php index 4f4a7112d33d..afc48afbc21f 100644 --- a/app/Models/Vendor.php +++ b/app/Models/Vendor.php @@ -216,8 +216,8 @@ class Vendor extends EntityModel { $publicId = isset($data['public_id']) ? $data['public_id'] : (isset($data['id']) ? $data['id'] : false); - if ($publicId && $publicId != '-1') { - $contact = VendorContact::scope($publicId)->firstOrFail(); + if (! $this->wasRecentlyCreated && $publicId && $publicId != '-1') { + $contact = VendorContact::scope($publicId)->whereVendorId($this->id)->firstOrFail(); } else { $contact = VendorContact::createNew(); }