Laravel-Model-Validation
Laravel-Model-Validation copied to clipboard
show the error messages in ajax
i used your validation library . its nice and helped a lot to me . but now i am getting one issue . i need to show the error messages only as a response . how can i achieve this ?
my code is
$dog = new dog(Input::all());
if (Request::ajax()) {
if (!$dog->save()) {
if ($dog->hasErrors()) {
return Response::json(array(
'success' => false,
'errors' => $dog->getErrors(),
), 200);
}
}
}
This isn't a bug. You can include the errors in an Ajax response by calling $dog->getErrors()->toArray()
. This is necessary as the messages attribute of the object returned by getErrors() is protected