I am creating app in laravel 5.8
I am using http://autonumeric.org/ for my price field in order to separate every three digits with comma. So for a number with more than 3 digits it will have a comma.
Input validation for integer fails if I enter more than 3 digits!. Obviously it is because of the comma. Therefore I tried sanitizing the input before validation. but the problem remains!
I tried to cast the sanitized versions of inputs to int but it still does not work!
This is how my request class look like:
public function rules()
{
$this->sanitize();
return [
'base_price' => 'required|integer', //it fails if I enter a number with more than 3 digits!
];
}
public function sanitize()
{
$input = $this->all();
//sanitize
$input['base_price'] = filter_var($input['base_price'], FILTER_SANITIZE_NUMBER_INT);
//casting
$input['base_price'] = (int) $input[base_price'];
$this->replace($input);
}