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
I have a personas repeater with one, or more persona in it. Each persona has a name, and slug. One, one only one, of the persona must have a slug set to 'guide'. Here is how I solved that validation (with help from examining ->distinct, and a bit of chatgpt 4o)
So, my form schema starts like this
And the validation looks like this:
privatestaticfunctionValidateOneAndExactlyOne_forGivenValueWithinRepeater(string$valueWeNeedOne_andExactlyOne_of, Closure$fail, Component$component, string$failureMessage): bool
{
// Get the parent repeater$repeater = $component->getParentRepeater();
// Get the state path of the repeater$repeaterStatePath = $repeater->getStatePath();
// Extract the component item state path relative to the repeater$componentItemStatePath = (string) str($component->getStatePath())
->after("{$repeaterStatePath}.")
->after('.');
// Get the state of the repeater$repeaterState = $repeater->getState();
// Get all the slugs in the repeater$slugs = Arr::pluck($repeaterState, $componentItemStatePath);
// Count occurrences of the specific slug value$slugCount = collect($slugs)->countBy()->get($valueWeNeedOne_andExactlyOne_of, 0);
// Validate that the value exists exactly onceif ($slugCount !== 1) {
$fail($failureMessage);
}
returntrue;
}
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
-
I have a
personas
repeater with one, or morepersona
in it. Each persona has aname
, andslug
. One, one only one, of the persona must have a slug set to 'guide'. Here is how I solved that validation (with help from examining ->distinct, and a bit of chatgpt 4o)So, my form schema starts like this
And the validation looks like this:
Beta Was this translation helpful? Give feedback.
All reactions