You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my application, I want to disable some buttons if my_array is invalid.
I needed to change in my request the filterPrecognitiveRules function.
ORIGINAL
public function filterPrecognitiveRules($rules): array
{
if (! $this->headers->has('Precognition-Validate-Only')) {
return $rules;
}
return (new Collection($rules))
->only(explode(',', $this->header('Precognition-Validate-Only')))
->all();
}
MY UPDATE
public function filterPrecognitiveRules($rules): array
{
if (! $this->headers->has('Precognition-Validate-Only')) {
return $rules;
}
$onlyKeys = (new Collection(explode(',', $this->header('Precognition-Validate-Only'))))
->reduce(function (Collection $acc, string $name) use ($rules) {
return collect($rules)
->keys()
->filter(fn (string $key) => Str::of($key)->startsWith("{$name}.") || $key === $name)
->merge($acc);
}, collect())
->unique()
->all();
return (new Collection($rules))
->only($onlyKeys)
->all();
}
But in my REACT application, I want to use form.validate('myarray') to check if I have any errors withform.invalid('my_array') to get all errors from my_array, even children elements.
my_array is valid, but not my_array.0.last_name
I don't want to loop on every possible keys in my array to check if each attribute is in error.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone,
I have a problem with precognition. I hope some people can help me or improve laravel framework
My rules
In my application, I want to disable some buttons if my_array is invalid.
I needed to change in my request the
filterPrecognitiveRules
function.ORIGINAL
MY UPDATE
But in my REACT application, I want to use
form.validate('myarray')
to check if I have any errors withform.invalid('my_array')
to get all errors frommy_array
, even children elements.my_array
is valid, but notmy_array.0.last_name
I don't want to loop on every possible keys in my array to check if each attribute is in error.
What do you think ?
Thank you very much
Beta Was this translation helpful? Give feedback.
All reactions