Merge pull request #3152 from CihanSenturk/fix-item-price-max-size

Fixed item price fields max size validation
This commit is contained in:
Cüneyt Şentürk 2024-04-25 13:13:28 +01:00 committed by GitHub
commit 1e614c8475
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 25 additions and 0 deletions

View File

@ -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]),
];
}
}