Issue
Attribute names are replaced. E.g 'from_account_id' to 'from account id'
{
"errors": {
"to_account_id": [
"The to account id field and from account id must be different."
],
}
}
Option #1
Declare the attribute names in translations
$this->validate($request, [
'from_account_id' => 'required|integer',
'to_account_id' => 'required|integer|different:from_account_id',
]);
lang/en/validation.php
return [
'attributes' => [
+ 'from_account_id' => 'from_account_id',
+ 'to_account_id' => 'to_account_id',
],
];
Option #2
Pass the attribute names to the validator
$rules = [
'from_account_id' => 'required|integer',
'to_account_id' => 'required|integer|different:from_account_id',
];
$attributes = [
'from_account_id' => 'from_account_id',
'to_account_id' => 'to_account_id',
];
$validator = Validator::make($request->all(), $rules, $messages = [], $attributes);
$validator->validate();
Results
{
"errors": {
"to_account_id": [
"The to_account_id field and from_account_id must be different."
],
}
}