Skip to content

Instantly share code, notes, and snippets.

@nmfzone
Last active November 23, 2016 05:42
Show Gist options
  • Select an option

  • Save nmfzone/050d948ab9d10c1ddfec04981b568f65 to your computer and use it in GitHub Desktop.

Select an option

Save nmfzone/050d948ab9d10c1ddfec04981b568f65 to your computer and use it in GitHub Desktop.
Custom Validation
Validator::extend('different_if_present', function($attribute, $value, $parameters, $validator) {
$otherValue = Arr::get($validator->getData(), $parameters[0]);
return $value !== $otherValue;
});
Validator::replacer('different_if_present', function($message, $attribute, $rule, $parameters) {
return str_replace(':other', $parameters[0], $message);
});
// How to use
'address1' => 'required|different_if_present:address2',
'address2' => 'different_if_present:address1',
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment