Skip to content

Instantly share code, notes, and snippets.

@jasonlbeggs
Created March 5, 2021 01:45
Show Gist options
  • Save jasonlbeggs/6a02cf32d1bcd383cab212687e4cdbd1 to your computer and use it in GitHub Desktop.
Save jasonlbeggs/6a02cf32d1bcd383cab212687e4cdbd1 to your computer and use it in GitHub Desktop.

Same Validation Rule

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'
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment