Do you have some guides for creating your own Repeater?
I have tried making my own repeater component and honestly I have a bit of trouble implementing it (I used the default repeaters blade design). It has lots a problems especially for when generating a new data. I get a missing column even though I manually specified it.
Do you have a good guide for making your own custom component? Using 3.x btw

5 Replies
Answers::make('options')
->label('Possible Answers')
->relationship('options')
->reorderable()
->simple(TextInput::make('label'))
->deleteAction(fn(Forms\Components\Actions\Action $action) =
> $action->requiresConfirmation(), )
->deleteAction(
fn(Forms\Components\Actions\Action $action) =
>
$action->link()
->label('Delete Answer')
->icon('heroicon-o-trash')
->color('danger')
->action(function(Forms\Get $get, Forms\Set $set,
array $state, array $arguments) {
$questionOptionID =
isset($arguments['item'])
? (int)str_replace('record-', '',
$arguments['item'])
: null;
if (!$questionOptionID) {
throw new \Exception('UUID not provided for deletion.');
}
QuestionOption::findOrFail($questionOptionID)->delete ();
$updatedState =
array_filter($state, fn($option) = > $option['id'] !=
= $questionOptionID);
$set('options', array_values($updatedState));
})),
Answers::make('options')
->label('Possible Answers')
->relationship('options')
->reorderable()
->simple(TextInput::make('label'))
->deleteAction(fn(Forms\Components\Actions\Action $action) =
> $action->requiresConfirmation(), )
->deleteAction(
fn(Forms\Components\Actions\Action $action) =
>
$action->link()
->label('Delete Answer')
->icon('heroicon-o-trash')
->color('danger')
->action(function(Forms\Get $get, Forms\Set $set,
array $state, array $arguments) {
$questionOptionID =
isset($arguments['item'])
? (int)str_replace('record-', '',
$arguments['item'])
: null;
if (!$questionOptionID) {
throw new \Exception('UUID not provided for deletion.');
}
QuestionOption::findOrFail($questionOptionID)->delete ();
$updatedState =
array_filter($state, fn($option) = > $option['id'] !=
= $questionOptionID);
$set('options', array_values($updatedState));
})),

Or if I add two Items and delete the newly added one, this will also happen

addAction()
->addAction(fn(Forms\Components\Actions\Action $action) =
> $action->link()
->label('Add an Answer')
->icon('heroicon-o-plus')
->action(function(Forms\Get $get, Forms\Set $set,
array $state) {
$uuid = Str::uuid()->toString();
$state[] = [
'uuid' = > $uuid,
'label' = > '',
'is_correct' = > false,
'disabled' =
> false, // disable newly added item to options
'ordinal' = > count($state),
];
Question::find($get('id'))->options()->create([
'label' = > '',
'ordinal' = > count($state),
'uuid' = > $uuid,
'is_correct' = > false,
]);
$set('options', $state);
}))
->addAction(fn(Forms\Components\Actions\Action $action) =
> $action->link()
->label('Add an Answer')
->icon('heroicon-o-plus')
->action(function(Forms\Get $get, Forms\Set $set,
array $state) {
$uuid = Str::uuid()->toString();
$state[] = [
'uuid' = > $uuid,
'label' = > '',
'is_correct' = > false,
'disabled' =
> false, // disable newly added item to options
'ordinal' = > count($state),
];
Question::find($get('id'))->options()->create([
'label' = > '',
'ordinal' = > count($state),
'uuid' = > $uuid,
'is_correct' = > false,
]);
$set('options', $state);
}))
deleteAction()
->deleteAction(
fn(Forms\Components\Actions\Action $action) =
> $action->link()
->label('Delete Answer')
->icon('heroicon-o-trash')
->color('danger')
->action(function(Forms\Get $get, Forms\Set $set, array $state,
array $arguments) {
$questionOptionID =
isset($arguments['item'])
? (int)str_replace('record-', '', $arguments['item'])
: null;
if (!$questionOptionID) {
throw new \Exception('UUID not provided for deletion.');
}
QuestionOption::findOrFail($questionOptionID)->delete ();
$updatedState =
array_filter($state, fn($option) = > $option['id'] !=
= $questionOptionID);
$set('options', array_values($updatedState));
})),
->deleteAction(
fn(Forms\Components\Actions\Action $action) =
> $action->link()
->label('Delete Answer')
->icon('heroicon-o-trash')
->color('danger')
->action(function(Forms\Get $get, Forms\Set $set, array $state,
array $arguments) {
$questionOptionID =
isset($arguments['item'])
? (int)str_replace('record-', '', $arguments['item'])
: null;
if (!$questionOptionID) {
throw new \Exception('UUID not provided for deletion.');
}
QuestionOption::findOrFail($questionOptionID)->delete ();
$updatedState =
array_filter($state, fn($option) = > $option['id'] !=
= $questionOptionID);
$set('options', array_values($updatedState));
})),