i use ajax to send my request , and i want to format errors in special way (still jason though .. i want to change data structure of error and add some flags to it )
so since apparently $this->validate
just would print out errors without my permission ! and i have no control over it , i have to use static method of validator
$whitelist = [
'title'=>'required',
'slug'=>'present' ,
'text'=>'present'
];
$validation = Validator::make($request->all(), $whitelist);
if($validation->fails())
{
format_output_likeIwant($validation->messages()->messages());
}
$another_whitelist = [
'some_other_info'=>'required',
];
just out of curiosity , is there any way for me to validate my $another_whitelist
with my existing instance ? or should i create a new instance of validator for each list ?
btw reason for having 2 different validation array is , i'm using this whitelists/arrays to populate my model instance before save/update in database and avoid writing lots of extra code in case of big tables.. 2 list here belong to different model/tables (see here for example)
i've looked in the laravel documentation , it seems all of the examples assume single validation list
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2aUnEcb
via IFTTT
Aucun commentaire:
Enregistrer un commentaire