public function addContact($data, $isPrimary = false)
{
$publicId = isset($data['public_id']) ? $data['public_id'] : (isset($data['id']) ? $data['id'] : false);
if ($publicId && $publicId != '-1') {
$contact = Contact::scope($publicId)->firstOrFail();
} else {
$contact = Contact::createNew();
$contact->send_invoice = true;
}
if (Utils::hasFeature(FEATURE_CLIENT_PORTAL_PASSWORD) && $this->account->enable_portal_password) {
if (!empty($data['password']) && $data['password'] != '-%unchanged%-') {
$contact->password = bcrypt($data['password']);
} else {
if (empty($data['password'])) {
$contact->password = null;
}
}
}
$contact->fill($data);
$contact->is_primary = $isPrimary;
return $this->contacts()->save($contact);
}