Ensure documents array is an array

This commit is contained in:
David Bomba 2022-09-06 17:36:56 +10:00
parent 4b0b32ed5b
commit bfff515b59
3 changed files with 10 additions and 1 deletions

View File

@ -65,7 +65,7 @@ class StoreClientRequest extends Request
/* Ensure we have a client name, and that all emails are unique*/
//$rules['name'] = 'required|min:1';
$rules['settings'] = new ValidClientGroupSettingsRule();
$rules['contacts'] = 'array';
$rules['contacts'] = 'bail|array';
$rules['contacts.*.email'] = 'bail|nullable|distinct|sometimes|email';
$rules['contacts.*.password'] = [
'bail',

View File

@ -28,6 +28,7 @@ class ClientContactRepository extends BaseRepository
public function save(array $data, Client $client) : void
{
if (isset($data['contacts'])) {
$contacts = collect($data['contacts']);
} else {
@ -43,8 +44,13 @@ class ClientContactRepository extends BaseRepository
$this->set_send_email_on_contact = true;
}
nlog($contacts->toArray());
/* Set first record to primary - always */
$contacts = $contacts->sortByDesc('is_primary')->map(function ($contact) {
nlog($contact);
$contact['is_primary'] = $this->is_primary;
$this->is_primary = false;

View File

@ -33,6 +33,9 @@ trait SavesDocuments
return false;
}
if(!is_array($document_array))
return;
foreach ($document_array as $document) {
$document = (new UploadFile(
$document,