© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
1 reply
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!
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Select field hasMany relation
FilamentFFilament / ❓┊help
3y ago
Nested relation
FilamentFFilament / ❓┊help
3y ago
translate relation manager tabs
FilamentFFilament / ❓┊help
3y ago