I have a form with 3 fields. 1 field is inside a repeater and the other 2 are not, as they are common to all records. If the user enters 10 repeaters, 10 records will be persisted.
What I did to make it work is customize the creation process inside my create page class:
protected function handleRecordCreation(array $data): Model{ // pseudo code foreach (myrepeater as repeater) { $models[] = static::getModel()::create($repeater_and_common_data) } // just to be compliance with the return type return $models[0];}
protected function handleRecordCreation(array $data): Model{ // pseudo code foreach (myrepeater as repeater) { $models[] = static::getModel()::create($repeater_and_common_data) } // just to be compliance with the return type return $models[0];}
My question is: Is this the way to go or does this code smell bad?