Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Spark - no AJAX fields validation errors on register

I just installed a Laravel Spark v4 - ran spark new project-name and followed the steps without any errors, the issue is that register form does not show any validation errors, not inline red warnings when input is not filled in or validation after the form is sent, what can be the issue? have not changed the generic register blade files.

When nothing is entered I get response code:

app.js:6175 POST http://127.0.0.1:8000/register 422 (Unprocessable Entity)

And the correct JSON response:

{"message":"The given data was invalid.","errors":{"name":["The name field is required."],"email":["The email field is required."],"password":["The password field is required."],"terms":["The terms must be accepted."]}}

Laravel's basic validation works on register form, but it does not work with AJAX request on login / register forms. Forms itself works when registering new users - but no feedback to the user.

like image 613
Marcin Avatar asked Dec 07 '25 08:12

Marcin


2 Answers

I believe this has to do with Laravel's "Consistent Exception Handling" under the hood. The VueJS application for Spark isn't yet taking this into consideration.

To fix locally, around line 54 of /spark/resources/assets/js/forms/errors.js, in the this.set function, change:

if (typeof errors === 'object') {
        this.errors = errors;
    } else {...

to

if (errors.errors && (typeof errors.errors === 'object')){
        this.errors = errors.errors;
    } else {...

Recompile your JS, and it should begin working again.

like image 195
Paul Grimes Avatar answered Dec 10 '25 00:12

Paul Grimes


I got the same problem right now after a new installation. I changed the code according to Paul's answer but it still doesn't work. Maybe the reason is that i don't know how to recompile the JS...

I did: rerun npm run dev, run php artisan view:clear, run php artisan cache:clear but this all didn't help. Sorry I'm totally new to laravel

like image 32
Bernd Da Avatar answered Dec 09 '25 23:12

Bernd Da



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!