Return blank Backup object if none exists

This commit is contained in:
David Bomba 2021-09-30 04:58:48 +10:00
parent 34a90d2ba8
commit 43822fbfdd
2 changed files with 15 additions and 4 deletions

View File

@ -80,10 +80,10 @@ class ClientContactRepository extends BaseRepository
});
//need to reload here to shake off stale contacts
$client->load('contacts');
$client->fresh();
//always made sure we have one blank contact to maintain state
if ($client->contacts->count() == 0) {
if ($client->contacts()->count() == 0) {
$new_contact = ClientContactFactory::create($client->company_id, $client->user_id);
$new_contact->client_id = $client->id;
$new_contact->contact_key = Str::random(40);

View File

@ -29,8 +29,19 @@ class InvoiceHistoryTransformer extends EntityTransformer
public function transform(?Backup $backup)
{
if(!$backup)
return null;
if(!$backup){
return [
'id' => '',
'activity_id' => '',
'json_backup' => (string) '',
'html_backup' => (string) '',
'amount' => (float) 0,
'created_at' => (int) 0,
'updated_at' => (int) 0,
];
}
return [
'id' => $this->encodePrimaryKey($backup->id),