Hello, I have something similar, did you find a nice solution, thanks
Spark::validateUsersWith() closure in SparkServiceProvider is called twice
I'm working on a project that's based on Spark 2.0 (can't update it at the moment) and I'm trying to add reCaptcha validation to the registration page. I'm using the latest version anhskohbo/no-captcha for this and it works fine when called in my controllers, but fails when used on the spark's registration page.
Problem is that for some reason the custom user validation rules from Spark::validateUsersWith() are called twice by Spark, so the 2nd time captcha fails (as it was already successfully tested first time). I tried tracing the calls, but since there's a lot of "magic" in how interact() works I couldn't figure out why it's called twice.
Here are my validation rules from SparkServiceProvider, called inside the booted() method:
Spark::validateUsersWith(function ($request) {
return [
'name' => 'required|max:255',
'email' => 'required|email|confirmed|max:255|unique:users',
'password' => 'required|confirmed|min:8',
'tz_name' => 'required|timezone',
'terms' => 'required|accepted',
'g-recaptcha-response' => 'required|captcha',
];
});
This is more or less the same code that comes with Spark, I just added a few rules to the end.
For some reason this closure is called twice during the registration process, with exactly the same arguments. This is no big problem for the idempotent rules like max length, but since captcha can't be tested twice with the same value it fails and breaks the registration page.
Does anyone know why validation is run twice and can that be avoided? Would upgrading Spark to the current version help?
I hacked a quick solution to ignore the second call, but I'd prefer to know where this comes from...
Please or to participate in this conversation.