I'm trying laravel required
validator in my code, unfortunately it fails for even empty string. I do not want it fail for empty string.
$validator = \Validator::make(array("name"=>""), array("name"=>"required"));
if ($validator->fails()){
var_dump($validator->messages());
} else {
die("no errors :)");
}
It gives me the following output
object(Illuminate\Support\MessageBag)[602]
protected 'messages' =>
array (size=1)
'name' =>
array (size=1)
0 => string 'The name field is required.' (length=27)
protected 'format' => string ':message' (length=8)
It is supposed to pass, since i'm giving an empty string as the name
field.
The above behavior happens in OSX environment (PHP Version 5.5.18), but it works fine in linux environment (PHP Version 5.5.9-1ubuntu4.5).
php", to replace the :attribute name (input name) for a proper to read name (example: first_name > First name) . It seems very simple to use, but the validator doesn't show the "nice names". And the validation in the controller: $validation = Validator::make($input, $rules, $messages);
By default, Laravel 'confirmed' validator adds the error message to the original field and not to the field which usually contains the confirmed value.
I use this:
'my_field' => 'present'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With