mardi 4 août 2015

How to push only validation error messages into an array using Laravel

I have a validator, it has error messages, and my goal is to get only error messages with the field names.

$validator = Validator::make(
   array(
      'firstField' => Input::get('firstFieldName');
      'secondField' => Input::get('secondFieldName');
   ),
   array(
      'firstField' => 'required';
      'secondField' => 'required';
   )
);

if($validator->fails()){
   return $validator->messages();
}

So, this piece of code is returning some values to my js file as following

function getErrorMessages(){
   //Some UI functions
   var myDiv = document.getElementById('messageDivID');
   $.post('validationRoute', function(returedValidatorMessageData)){
      for(var a in returedValidatorMessageData){
         myDiv.innerHTML = myDiv.value + a;
      }
   }
}

Problem is, the only values i get from post request is like firstField secondField but i'd like to get like firstField is required message. What would be the easiest way ?

Thanks in advance.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire