2017-01-30 20:40:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Ninja\Repositories;
|
2015-12-07 22:41:48 +01:00
|
|
|
|
|
|
|
use App\Models\Contact;
|
|
|
|
|
|
|
|
class ContactRepository extends BaseRepository
|
|
|
|
{
|
|
|
|
public function save($data)
|
|
|
|
{
|
|
|
|
$publicId = isset($data['public_id']) ? $data['public_id'] : false;
|
|
|
|
|
2017-01-30 20:40:43 +01:00
|
|
|
if (! $publicId || $publicId == '-1') {
|
2015-12-07 22:41:48 +01:00
|
|
|
$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;
|
2016-05-24 20:16:42 +02:00
|
|
|
$contact->contact_key = str_random(RANDOM_KEY_LENGTH);
|
2015-12-07 22:41:48 +01:00
|
|
|
} else {
|
|
|
|
$contact = Contact::scope($publicId)->firstOrFail();
|
|
|
|
}
|
|
|
|
|
|
|
|
$contact->fill($data);
|
|
|
|
$contact->save();
|
|
|
|
|
|
|
|
return $contact;
|
|
|
|
}
|
2017-01-30 17:05:31 +01:00
|
|
|
}
|