Laravel custom validation - get parameters
As a 4th the whole validator is passed to the closure you define with extends
. You can use that to get the all data which is validated:
Validator::extend('event_sponsor', function ($attribute, $value, $parameters, $validator) {
$sponsor_id = array_get($validator->getData(), $parameters[0], null);
// ...
});
By the way I'm using array_get
here to avoid any errors if the passed input name doesn't exist.