I've created custom validator:
namespace App\Validators;
class PhoneValidationRule extends \Illuminate\Validation\Validator {
public function validatePhone($attribute, $value, $parameters)
{
return preg_match("/^[\+]?[-()\s\d]{4,17}$/", $value);
}
}
and registered it:
class ValidatorServiceProvider extends ServiceProvider {
public function boot()
{
\Validator::resolver(function($translator, $data, $rules, $messages)
{
return new PhoneValidationRule($translator, $data, $rules, $messages);
});
}
...
and it works fine if i call it for field:
$validator = Validator::make($input, [
'emails' => 'required|each:email',
'phone' => 'required|phone',
]);
but when i try to apply it for array:
$validator = Validator::make($input, [
'emails' => 'required|each:email',
'phones' => 'required|each:phone',
]);
i get error message:
error: {type: "BadMethodCallException", message: "Method [validateEach] does not exist.",…} file: "/home/.../vendor/laravel/framework/src/Illuminate/Validation/Validator.php" line: 2564 message: "Method [validateEach] does not exist." type: "BadMethodCallException"
what i'm doing wrong?
each
. Is this a custom rule? – Mozammil