Home>

There is a code:


Laravel:

Function Signup (Request $ REQ)
    {
        $ validation= Validator :: Make ($ Req->
All (),
    [
        'name'= >
'Required',
        'Surname'= >
'Required',
        'email'= >
'Required | Unique: Users | Email',
        'password'= >
'Required',
    ]);
    if ($ validation->
fails ())
    {
        RETURN RESPONSE () ->
JSON ([
            'Code'= >
422,
            'Content'= >
$ Validation->
Errors ()
        ], 422);
    }
    User :: Create ($ REQ->
All ());
    RETURN RESPONSE () ->
JSON (['Code'= >
200]) ->
SetStatuscode (200);
    }



javascript:

Registration () {
            $.ajax ({
                Type: "POST",
                URL: "http://127.0.0.1:8000/api/signup",
                Data: {
                    Name: this.registrationForm.Name,
                    Surname: this.registrationForm.Surname,
                    Email: this.registrationForm.Email,
                    Password: this.registrationForm.password,
                }
                SUCCESS: FUNCTION (DATA) {app.showsuccess ('You have successfully registered')},
                Error: Function (JQXhr, TextStatus, Errorthrown) {console.log (jqxhr); Console.log (TextStatus); Console.log (Errorthrown)},
            });
            RETURN FALSE;
        }

essence of the question:

The server returns an error, and I need data on validation ... Ie, the server must return

{
            'Code': 422,
            'Content'= >
(there is friends to be mistakes)
}

I think the problem in 422 HTTP code.

Thanks in advance to everyone!

The server returns an error and this is the right behavior in this case. You have an error input data so there is a validation error, for processing this error you need to get data in your anonymous function in JS ->Error: Function (JQXhr, TextStatus, Errorthrown) and already There, something to manipulate the messages about the validation error that the server gives you.

Абдуллаев Мухаммед2021-05-11 10:01:43