1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Ninja/Repositories/ContactRepository.php

31 lines
871 B
PHP
Raw Normal View History

2017-01-30 20:40:43 +01:00
<?php
namespace App\Ninja\Repositories;
use App\Models\Contact;
class ContactRepository extends BaseRepository
{
2017-03-27 10:36:48 +02:00
public function save($data, $contact = false)
{
$publicId = isset($data['public_id']) ? $data['public_id'] : false;
2017-03-27 10:36:48 +02:00
if ($contact) {
// do nothing
} elseif (! $publicId || $publicId == '-1') {
$contact = Contact::createNew();
$contact->send_invoice = true;
$contact->client_id = $data['client_id'];
$contact->is_primary = Contact::scope()->where('client_id', '=', $contact->client_id)->count() == 0;
2017-04-02 19:46:01 +02:00
$contact->contact_key = strtolower(str_random(RANDOM_KEY_LENGTH));
} else {
$contact = Contact::scope($publicId)->firstOrFail();
}
$contact->fill($data);
$contact->save();
return $contact;
}
2017-01-30 17:05:31 +01:00
}