diff --git a/app/Ninja/Repositories/VendorRepository.php b/app/Ninja/Repositories/VendorRepository.php index 0dbb43ebd814..43500c0f1ae2 100644 --- a/app/Ninja/Repositories/VendorRepository.php +++ b/app/Ninja/Repositories/VendorRepository.php @@ -85,12 +85,22 @@ class VendorRepository extends BaseRepository $first = true; $vendorcontacts = isset($data['vendor_contact']) ? [$data['vendor_contact']] : $data['vendor_contacts']; + $vendorcontactIds = []; foreach ($vendorcontacts as $vendorcontact) { $vendorcontact = $vendor->addVendorContact($vendorcontact, $first); + $vendorcontactIds[] = $vendorcontact->public_id; $first = false; } + if ( ! $vendor->wasRecentlyCreated) { + foreach ($vendor->vendor_contacts as $contact) { + if (!in_array($contact->public_id, $vendorcontactIds)) { + $contact->delete(); + } + } + } + return $vendor; } }