In RelationshipManager modal form, how I can validate Repeater form
Please advise how I make a proper livewire->validate() the Repeater Data form.
The data is in array as $data['transfer'] . At the moment I just made if(!blank($transferData['from_id']) ...
I would like to use $livewire->validate(
'to_id'=>['required'],
)
but how to put Repeater in to validate
->headerActions([
->action(function ($data, RelationManager $livewire) {
if ($data['transfers']) {
$employee = $livewire->getOwnerRecord();
foreach ($data['transfers'] as $transfer) {
if (!$livewire->validateForm($data, $transfer)) return;
$newRecord = new Transfer();
$newRecord->from_id = $transfer['from_id'];
$newRecord->to_id = $transfer['to_id'];
$newRecord->transfer_type = $transfer['transfer_type'];
$newRecord->employee_id = $livewire->getOwnerRecord()->id;
$newRecord->transfer_date = $data['transfer_date'];
$newRecord->effective_date = $data['effective_date'];
$newRecord->before_detail = EmployeeResource::getEmploymentDetail($livewire->getOwnerRecord());
$records[] = $newRecord;
$fieldId = strtolower(Str::snake(class_basename($transfer['transfer_type']))) . '_id';
$employee->$fieldId = $transfer['to_id'];
}
$livewire->updateAfterDetail($records, $employee);
$employee->save();
}
})
->headerActions([
->action(function ($data, RelationManager $livewire) {
if ($data['transfers']) {
$employee = $livewire->getOwnerRecord();
foreach ($data['transfers'] as $transfer) {
if (!$livewire->validateForm($data, $transfer)) return;
$newRecord = new Transfer();
$newRecord->from_id = $transfer['from_id'];
$newRecord->to_id = $transfer['to_id'];
$newRecord->transfer_type = $transfer['transfer_type'];
$newRecord->employee_id = $livewire->getOwnerRecord()->id;
$newRecord->transfer_date = $data['transfer_date'];
$newRecord->effective_date = $data['effective_date'];
$newRecord->before_detail = EmployeeResource::getEmploymentDetail($livewire->getOwnerRecord());
$records[] = $newRecord;
$fieldId = strtolower(Str::snake(class_basename($transfer['transfer_type']))) . '_id';
$employee->$fieldId = $transfer['to_id'];
}
$livewire->updateAfterDetail($records, $employee);
$employee->save();
}
})
0 Replies