From bfff515b5974de4273144059398473e2ca768b59 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 6 Sep 2022 17:36:56 +1000 Subject: [PATCH] Ensure documents array is an array --- app/Http/Requests/Client/StoreClientRequest.php | 2 +- app/Repositories/ClientContactRepository.php | 6 ++++++ app/Utils/Traits/SavesDocuments.php | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/Http/Requests/Client/StoreClientRequest.php b/app/Http/Requests/Client/StoreClientRequest.php index 463cc7b4a355..48e4d095c36d 100644 --- a/app/Http/Requests/Client/StoreClientRequest.php +++ b/app/Http/Requests/Client/StoreClientRequest.php @@ -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', diff --git a/app/Repositories/ClientContactRepository.php b/app/Repositories/ClientContactRepository.php index e82b9efd07d5..8bd7e941b720 100644 --- a/app/Repositories/ClientContactRepository.php +++ b/app/Repositories/ClientContactRepository.php @@ -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; diff --git a/app/Utils/Traits/SavesDocuments.php b/app/Utils/Traits/SavesDocuments.php index 47b2e006870f..babed027615c 100644 --- a/app/Utils/Traits/SavesDocuments.php +++ b/app/Utils/Traits/SavesDocuments.php @@ -33,6 +33,9 @@ trait SavesDocuments return false; } + if(!is_array($document_array)) + return; + foreach ($document_array as $document) { $document = (new UploadFile( $document,