Sending ajax request with form serialize data to controller and validating there but keep showing error even field is already filled with data.
var formData = form.serialize();
$.ajax({
type: "POST",
url: url,
method: 'post',
data: {"data": formData},
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
dataType: "json",
public function store(Request $req)
{
parse_str($req->formData, $data);
$validator = Validator::make($data, [
'hotel_name' => 'required',
'company_name' => 'required|numeric',
'hotel_country' => 'required',
'hotel_city' => 'required|alpha',
'hotel_area' => 'required|alpha',
'hotel_address' => 'required|alpha_dash'
]);
if ($validator->fails()) {
return array(
'success' => false,
'errors' => $validator->getMessageBag()->toArray()
);
}
}
Keep returning false
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire