Unique validation rule in repeater

Has anybody already handles unique validation rule in combination with Repeater fields?
2 Replies
Daniel
DanielOP2y ago
Works, with some small adjustments:
->afterStateUpdated(function ($component, $state, $livewire) {
$items = $component->getContainer()->getParentComponent()->getOldState();
$livewire->resetErrorBag($component->getStatePath());
if (in_array($state, collect($items)->pluck($component->getName())->toArray())) {
$livewire->addError(
$component->getStatePath(),
__('validation.unique', ['attribute' => $component->getLabel()])
);
}
})
->afterStateUpdated(function ($component, $state, $livewire) {
$items = $component->getContainer()->getParentComponent()->getOldState();
$livewire->resetErrorBag($component->getStatePath());
if (in_array($state, collect($items)->pluck($component->getName())->toArray())) {
$livewire->addError(
$component->getStatePath(),
__('validation.unique', ['attribute' => $component->getLabel()])
);
}
})

Did you find this page helpful?