Laravel includes a same
validation rule that is very similar to the confirmed
rule, but gives you much more flexibility if needed.
Using the confirmed
rule, the confirmation field's name must match the original field's name with _confirmation
appended. Using the same
rule, the field names can be completely different.
// Using the `confirmed` rule
request()->validate([
'password' => 'confirmed'
]);
// Using the `same` rule
request()->validate([
'password' => 'same:password_confirmation'
]);
// `same` can be used with any two fields, regardless of their names
request()->validate([
'some_field' => 'same:some_other_field'
]);