I have debit field and debit field
<input type="text" class="form-control" name="debit" value="{{ isset($expense->debit) ? $expense->debit : old('debit')}}">
and
<input type="text" class="form-control" name="credit" value="{{ isset($expense->credit) ? $expense->credit: old('credit')}}">
i need to make sure the values are equal when submit the form.
i know I can do that if name them like this:
debit and debit_confirmation and in rule array
return Validator::make($data, [
'debit' => 'required|confirmed',
]);
but I don't want to change their names.
any build-in validation in laravel 5 do that.
You could use the same
validation rule to match the fields you want.
return Validator::make($data, [
'debit' => 'required|same:credit',
]);
You could take a look at the laravel documentation for more information about validation rules
Among many validators that Laravel offers there is one you're looking for: same. In order to validate if values of 2 different fields (field1, field2) match, you need to define the following rules
$rules = [
'field1' => 'same:field2'
];
You can see a list of all available validation rules here: http://laravel.com/docs/5.1/validation#available-validation-rules
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With