Вы можете использовать пользовательское правило проверки для этого. Там нет ничего встроенного, что позволяет сравнивать с одной из многих других областей. Ближайшая проверка - same
, но она проверяет только одно другое поле.
(я добавил dd()
для выгрузки данных, вы можете удалить их)
$values
будет то, что исходит от вашего ввода. $validationRules
можно настроить для ваших нужд.
Validator::extend('equals_one_of', function($attribute, $value, $parameters, \Illuminate\Validation\Validator $validator) {
$fields = $validator->getData(); // all posted values
foreach($parameters as $param) { // this is each of the comma separated fields in the validationRules array
if ($value == $fields[$param]) {
dd("matched");
return true;
}
}
dd("no match");
return false;
});
$values = [
'player1' => 'test1',
'player2' => 'test2',
'winner' => 'test1'
];
$validationRules = [
'player1' => 'required',
'player2' => 'required',
'winner' => 'required|equals_one_of:player1,player2'
];
$validate = Validator::make($values, $validationRules);
// use your validator as normal.
dd($validate->validate());