From e5df6754fe92ded3a9dc050e6fbd367095b86a9a Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 30 Apr 2025 13:33:35 +1000 Subject: [PATCH] Fixes for client validation --- .../StoreBankTransactionRequest.php | 2 ++ .../Requests/Client/StoreClientRequest.php | 24 ++++++++++++++--- .../Requests/Client/UpdateClientRequest.php | 26 ++++++++++++++++--- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/app/Http/Requests/BankTransaction/StoreBankTransactionRequest.php b/app/Http/Requests/BankTransaction/StoreBankTransactionRequest.php index e27abda0e6..86cb65c590 100644 --- a/app/Http/Requests/BankTransaction/StoreBankTransactionRequest.php +++ b/app/Http/Requests/BankTransaction/StoreBankTransactionRequest.php @@ -43,6 +43,8 @@ class StoreBankTransactionRequest extends Request $rules['bank_integration_id'] = 'bail|required|exists:bank_integrations,id,company_id,'.$user->company()->id.',is_deleted,0'; $rules['amount'] = ['sometimes', 'bail', 'numeric', 'nullable', 'max:99999999999999']; + $rules['base_type'] = ['required','in:debit,credit', 'bail']; + return $rules; } diff --git a/app/Http/Requests/Client/StoreClientRequest.php b/app/Http/Requests/Client/StoreClientRequest.php index 01924277ab..e56fb9b70d 100644 --- a/app/Http/Requests/Client/StoreClientRequest.php +++ b/app/Http/Requests/Client/StoreClientRequest.php @@ -75,10 +75,26 @@ class StoreClientRequest extends Request $rules['shipping_country_id'] = 'integer|nullable|exists:countries,id'; $rules['number'] = ['sometimes', 'nullable', 'bail', Rule::unique('clients')->where('company_id', $user->company()->id)]; $rules['country_id'] = 'integer|nullable|exists:countries,id'; - $rules['custom_value1'] = 'bail|nullable|sometimes|alpha_num'; - $rules['custom_value2'] = 'bail|nullable|sometimes|alpha_num'; - $rules['custom_value3'] = 'bail|nullable|sometimes|alpha_num'; - $rules['custom_value4'] = 'bail|nullable|sometimes|alpha_num'; + $rules['custom_value1'] = ['bail','nullable','sometimes',function ($attribute, $value, $fail) { + if (is_array($value)) { + $fail("The $attribute must not be an array."); + } + }]; + $rules['custom_value2'] = ['bail','nullable','sometimes',function ($attribute, $value, $fail) { + if (is_array($value)) { + $fail("The $attribute must not be an array."); + } + }]; + $rules['custom_value3'] = ['bail','nullable','sometimes',function ($attribute, $value, $fail) { + if (is_array($value)) { + $fail("The $attribute must not be an array."); + } + }]; + $rules['custom_value4'] = ['bail','nullable','sometimes',function ($attribute, $value, $fail) { + if (is_array($value)) { + $fail("The $attribute must not be an array."); + } + }]; return $rules; } diff --git a/app/Http/Requests/Client/UpdateClientRequest.php b/app/Http/Requests/Client/UpdateClientRequest.php index 908b4f0ca9..18783a68cb 100644 --- a/app/Http/Requests/Client/UpdateClientRequest.php +++ b/app/Http/Requests/Client/UpdateClientRequest.php @@ -75,10 +75,28 @@ class UpdateClientRequest extends Request //'regex:/[@$!%*#?&.]/', // must contain a special character ]; - $rules['custom_value1'] = 'bail|nullable|sometimes|alpha_num'; - $rules['custom_value2'] = 'bail|nullable|sometimes|alpha_num'; - $rules['custom_value3'] = 'bail|nullable|sometimes|alpha_num'; - $rules['custom_value4'] = 'bail|nullable|sometimes|alpha_num'; + + $rules['custom_value1'] = ['bail','nullable','sometimes',function ($attribute, $value, $fail) { + if (is_array($value)) { + $fail("The $attribute must not be an array."); + } + }]; + $rules['custom_value2'] = ['bail','nullable','sometimes',function ($attribute, $value, $fail) { + if (is_array($value)) { + $fail("The $attribute must not be an array."); + } + }]; + $rules['custom_value3'] = ['bail','nullable','sometimes',function ($attribute, $value, $fail) { + if (is_array($value)) { + $fail("The $attribute must not be an array."); + } + }]; + $rules['custom_value4'] = ['bail','nullable','sometimes',function ($attribute, $value, $fail) { + if (is_array($value)) { + $fail("The $attribute must not be an array."); + } + }]; + return $rules; }