Laravel-Model-Validation icon indicating copy to clipboard operation
Laravel-Model-Validation copied to clipboard

show the error messages in ajax

Open sureshamk opened this issue 10 years ago • 1 comments

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); 
                }
            }

        }

sureshamk avatar May 26 '14 12:05 sureshamk

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

molovo avatar Oct 17 '14 14:10 molovo