© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
1 reply
Luiz Cristino

Form Tabs not saving the correct relationship content.

So I have a form that has an Tab that handles the translation of some fields, like
title
title
and
description
description
of a model. What is happening is that for now the app has 3 basic languages, more will be add later. To make this possible every translatable model has an i18n table counterpart. This i18n has one column per translatable property of the model together with the composite primary key
model_id
model_id
and
locale
locale
, here is an example:

Table public.models
- id [pk]
- status
- created_at 
- updated_at

Table i18n.models
- model_id [pk] [fk public.models.id]
- locale [pk]
- title
- description
Table public.models
- id [pk]
- status
- created_at 
- updated_at

Table i18n.models
- model_id [pk] [fk public.models.id]
- locale [pk]
- title
- description


The example above shows that
Model
Model
will not have
title
title
and
description
description
fields. It will be saved on the i18n one with their respective locale,
en_CA
en_CA
,
fr_CA
fr_CA
and etc.

I built and trait that helps getting the correct model with above structure. Trait

What happens is that the correct values are shown, but when I press the save button, the current visible
Tab
Tab
overwrites all others locales. So if a save when
en_CA
en_CA
tab is visible, the tab holding the values for
fr_CA
fr_CA
will be overwritten.

Here is an simplified code of how
Tabs
Tabs
was built:

class ExampleResource extends Resource
{
  public static function form(Form $form): Form
  {
    return $form
      ->schema([
        Section::make('Core information')
          ->schema([
            Tabs::make()
              ->tabs([
                static::createLanguageTab('en_CA'),
                static::createLanguageTab('fr_CA'),
              ]),
          ]),
      ]);
  }

  private static function createLanguageTab($locale): Tabs\Tab
  {
    return Tab::make($locale)
      ->schema([
        Group::make()
          /** this will call the magic methods `intlEnCA` and `intlFrCA` */
          ->relationship('intl' . ucfirst(preg_replace('/_/', '', $locale)))
          ->schema([
            /** Necessary to create a new row */
            Components\Hidden::make('locale')->default($locale),
            Components\TextInput::make('title')->label('Title'),
            Components\TextInput::make('description')->label('description'),
          ]),
      ]);
  }
}
class ExampleResource extends Resource
{
  public static function form(Form $form): Form
  {
    return $form
      ->schema([
        Section::make('Core information')
          ->schema([
            Tabs::make()
              ->tabs([
                static::createLanguageTab('en_CA'),
                static::createLanguageTab('fr_CA'),
              ]),
          ]),
      ]);
  }

  private static function createLanguageTab($locale): Tabs\Tab
  {
    return Tab::make($locale)
      ->schema([
        Group::make()
          /** this will call the magic methods `intlEnCA` and `intlFrCA` */
          ->relationship('intl' . ucfirst(preg_replace('/_/', '', $locale)))
          ->schema([
            /** Necessary to create a new row */
            Components\Hidden::make('locale')->default($locale),
            Components\TextInput::make('title')->label('Title'),
            Components\TextInput::make('description')->label('description'),
          ]),
      ]);
  }
}
Gist
Laravel Translatable model with magic method
Laravel Translatable model with magic method. GitHub Gist: instantly share code, notes, and snippets.
Laravel Translatable model with magic method
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Relationship manager form tabs
FilamentFFilament / ❓┊help
3y ago
Combine Relationship Manager tabs and form tabs
FilamentFFilament / ❓┊help
15mo ago
Relationship in Form not saving on create action.
FilamentFFilament / ❓┊help
3y ago
saving form fields to a single relationship
FilamentFFilament / ❓┊help
3y ago