F
Filament5mo ago
Tudor

Is it possible to save a resource in 3 tables with nested relationships?

Hello, I want to make a form for a wine preference quiz with this flow: - Question (text input) - saved with "Quiz " model - Answers (a repeater) - saved with "QuizAnswer" model - for each element from repeater I have an text field answer - and a multiple select field which should save the related wines to that question using QuizAnswerWine model.
public static function form(Form $form): Form
{
return $form
->schema([
Section::make('')
->description('Make a new quiz')
->schema([
Forms\Components\TextInput::make('question')
->label('Question')
->placeholder('Do you like sweet wines?')
->required(),
]),
Repeater::make('answers')
->relationship('answers') // Relationship name from Quiz to QuizAnswer
->schema([
Forms\Components\TextInput::make('answer')
->label('Answer')
->placeholder('Yes, I do!')
->required(),
Forms\Components\Select::make('answer_wines')
->label('Related Wines')
->relationship('answer_wines.wine', 'name') // Relationship name from QuizAnswer to QuizAnswerWine
->preload()
->multiple()
->required(),
])
]);
}
public static function form(Form $form): Form
{
return $form
->schema([
Section::make('')
->description('Make a new quiz')
->schema([
Forms\Components\TextInput::make('question')
->label('Question')
->placeholder('Do you like sweet wines?')
->required(),
]),
Repeater::make('answers')
->relationship('answers') // Relationship name from Quiz to QuizAnswer
->schema([
Forms\Components\TextInput::make('answer')
->label('Answer')
->placeholder('Yes, I do!')
->required(),
Forms\Components\Select::make('answer_wines')
->label('Related Wines')
->relationship('answer_wines.wine', 'name') // Relationship name from QuizAnswer to QuizAnswerWine
->preload()
->multiple()
->required(),
])
]);
}
this is my code, everything works good, only the last relationship with the related answer wines doesn't work, the save in DB it's not working, I have the wines in select.
No description
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server