diff --git a/app/Http/Requests/Common/Item.php b/app/Http/Requests/Common/Item.php index ede88c9fb..a4c7fa05e 100644 --- a/app/Http/Requests/Common/Item.php +++ b/app/Http/Requests/Common/Item.php @@ -32,6 +32,14 @@ class Item extends FormRequest $purchase_price = 'required'; } + if ($this->request->get('sale_price')) { + $sale_price .= $this->maxSizePrice($this->request->get('sale_price')); + } + + if ($this->request->get('purchase_price')) { + $purchase_price .= $this->maxSizePrice($this->request->get('purchase_price')); + } + return [ 'type' => 'required|string|in:product,service', 'name' => 'required|string', @@ -44,6 +52,21 @@ class Item extends FormRequest ]; } + public function maxSizePrice($price) + { + $size = 14; + + if (Str::contains($price, '.')) { + $size++; + } + + if (Str::contains($price, ',')) { + $size++; + } + + return '|max:' . $size; + } + public function messages() { $picture_dimensions = trans('validation.custom.invalid_dimension', [ @@ -54,6 +77,8 @@ class Item extends FormRequest return [ 'picture.dimensions' => $picture_dimensions, + 'sale_price.max' => trans('validation.max.numeric', ['max' => 14]), + 'purchase_price.max' => trans('validation.max.numeric', ['max' => 14]), ]; } }