3

I'm using a jquery repeater plugin and I need to post a json data which is repeater fields data to store method and back that data if there are validation errors. How that is possible?

Wreigh
  • 3,215
  • 16
  • 37
Ehsan Mousavi
  • 399
  • 1
  • 3
  • 10

1 Answers1

1

Use laravel builtin validations and it will return you back with errors (if any).

public function store(Request $request){
    $validator  = Validator::make($request,[
       'name' => 'required',
       //...
     ]);
   if($validator->fails()){
   return response()->json(['errors' => $validator->errors()]);
   }
} 

jQuery Side validate input on form submit

var name = $('#name').val();
if(name.length < -1){
   alert('name is required');
}
Afraz Ahmad
  • 5,193
  • 28
  • 38
  • how about the jquery side? I think that is the OP's main issue although it's not specified in the question. – Wreigh Aug 14 '18 at 05:04