F
Filament14mo ago
Laurens

Translate HasOne relation (with HasMany nested)

I'm creating a resource containing a HasOne relation which has a nested HasMany relation through a simple repeater. For translations I'm using the first party Spatie translatable package and setup the concerns in the Resource, List and Create/Edit pages. The main resource correctly gets translated and saved per locale in the JSON columns on the database. However, my relation saves the current locale to all locales. This is the setup I'm using currently:
Forms\Components\Group::make()
->schema([
Forms\Components\TextInput::make('question')
->label(trans('general.polls.attributes.question'))
->required()
->maxLength(255),
// Answers
Forms\Components\Repeater::make('answers')
->label(trans('general.polls.attributes.answers'))
->relationship('answers')
->simple(
Forms\Components\TextInput::make('name')
->required()
->maxLength(255)
)
->required()
->minItems(2)
->maxItems(5)
])
->relationship('poll')
->columnSpanFull()
->hidden(fn(Get $get) => !$get('options.enable_poll'))
Forms\Components\Group::make()
->schema([
Forms\Components\TextInput::make('question')
->label(trans('general.polls.attributes.question'))
->required()
->maxLength(255),
// Answers
Forms\Components\Repeater::make('answers')
->label(trans('general.polls.attributes.answers'))
->relationship('answers')
->simple(
Forms\Components\TextInput::make('name')
->required()
->maxLength(255)
)
->required()
->minItems(2)
->maxItems(5)
])
->relationship('poll')
->columnSpanFull()
->hidden(fn(Get $get) => !$get('options.enable_poll'))
While the poll and its answers get correctly saved in the correct poll -> poll_answers table with all relations setup, they're always saved to all locales instead of the active locales. Both the main Model as the nested Poll and PollAnswer models have the HasTranslations trait setup. What am I doing wrong here? Thanks in advance!
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server