Value in repeater is empty for each item
class TakeQuiz extends Component implements HasSchemas
{
use InteractsWithSchemas;
public array $data = [];
public QuizAttempt $attempt;
public function mount(QuizAttempt $attempt): void
{
$this->attempt = $attempt;
$this->form->fill([]);
}
public function form(Schema $schema): Schema
{
/** @var Quiz $quiz */
$quiz = $this->attempt->quiz;
return $schema
->statePath('data')
->model($quiz)
->columns(1)
->components([
Repeater::make('questions')
->hiddenLabel()
->relationship()
->itemLabel(fn (array $state): ?string => $state['title'] ?? 'Nieuwe vraag')
->schema([
Radio::make('answers')
->hiddenLabel()
->required()
->options(fn (QuizQuestion $record) => $record->options->pluck('option_text', 'id')->toArray())
->visible(fn (QuizQuestion $record) => $record->type === QuizQuestionType::SINGLE_CHOICE),
CheckboxList::make('answers')
->hiddenLabel()
->minItems(1)
->options(fn (QuizQuestion $record) => $record->options->pluck('option_text', 'id')->toArray())
->visible(fn (QuizQuestion $record) => $record->type === QuizQuestionType::MULTIPLE_CHOICE),
])
->orderColumn(false)
->deletable(false)
->addable(false)
]);
}
public function create(): void
{
$this->form->getState();
$data = $this->data;
dd($data);
}
}class TakeQuiz extends Component implements HasSchemas
{
use InteractsWithSchemas;
public array $data = [];
public QuizAttempt $attempt;
public function mount(QuizAttempt $attempt): void
{
$this->attempt = $attempt;
$this->form->fill([]);
}
public function form(Schema $schema): Schema
{
/** @var Quiz $quiz */
$quiz = $this->attempt->quiz;
return $schema
->statePath('data')
->model($quiz)
->columns(1)
->components([
Repeater::make('questions')
->hiddenLabel()
->relationship()
->itemLabel(fn (array $state): ?string => $state['title'] ?? 'Nieuwe vraag')
->schema([
Radio::make('answers')
->hiddenLabel()
->required()
->options(fn (QuizQuestion $record) => $record->options->pluck('option_text', 'id')->toArray())
->visible(fn (QuizQuestion $record) => $record->type === QuizQuestionType::SINGLE_CHOICE),
CheckboxList::make('answers')
->hiddenLabel()
->minItems(1)
->options(fn (QuizQuestion $record) => $record->options->pluck('option_text', 'id')->toArray())
->visible(fn (QuizQuestion $record) => $record->type === QuizQuestionType::MULTIPLE_CHOICE),
])
->orderColumn(false)
->deletable(false)
->addable(false)
]);
}
public function create(): void
{
$this->form->getState();
$data = $this->data;
dd($data);
}
}Can someone explain to me why I get
'answers' => []'answers' => [] for all my questions? I got this working earlier, but now I do not understand what I broke.