fixed item price fields max size validation
This commit is contained in:
parent
b3f74bd5e2
commit
f54dc146a1
|
|
@ -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]),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue