fixed item price fields max size validation

This commit is contained in:
Cihan Şentürk 2024-04-25 11:20:56 +03:00 committed by GitHub
parent b3f74bd5e2
commit f54dc146a1
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]),
];
}
}