Im trying to figure out how to quickly add error messages per field in Laravel 5. Here is what I got:
$validator = Validator::make($this->req->all(), [
'email_add' => 'required|email|max:100',
'pass' => 'required|max:20',
]);
So how do I put a message directly here for each field validated above? like "You forgot Email Address" and "Password is Required"?
(How to that without writing a mars rover program for 1 simple task. Like the usualy laravel 5 stuff of artisan make new something useless, add 2 namespaces, 3 middlewares, 5 classes, 7 functions and then finally override error messages!!)
[EDIT] After some help from answers below and other search on stack, I found exactly what is to be done:
Add a message for the
type
of validations per field:$validator = Validator::make($this->req->all(), [ 'email_add' => 'required|email|max:100', 'pass' => 'required|max:20', ], [ 'email_add.required' => 'The Email Address is actually required dude!', 'email_add.email' => 'The Email Address is is not a valid Email Address!' ]);
. .To just change the
email_add
intoEmail Address
, i.e. theAttribute Name
instead of writing a custom msg for every validation applied on every field:Validator::make(....)->setAttributeNames( [ 'email_add'=>'Email Address', 'pass'=>'Password' ]);
Thanks for the help guyz.