Repeater with key:value

I was able to get something working with repeater:

    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Section::make('Basic Information')
                    ->description('This is the basic information of the notification, provide all the relevant information including languages the default will be english')
                    ->schema([
                        Forms\Components\TextInput::make('name')
                            ->helperText('This is the name of the notification it is only seen internally')
                            ->maxLength(100),
                        Forms\Components\TextInput::make('path')
                            ->maxLength(1000),
                        ]),
                Section::make('Translations')
                    ->description('Add all your language translations for the notification that gets sent to the user here. If you do not add a translation the default will be english.')
                    ->schema([
                        Repeater::make('title')
                            ->schema([
                                Select::make('language_id')
                                    ->searchable()
                                    ->preload()
                                    ->relationship(name: 'language', titleAttribute: 'name'),
                                TextInput::make('text')->required(),
                            ])
                            ->addActionLabel('Add Another Language For Title')
                            ->columns(2)
                            ->rules([new EnglishTranslationMustExist()]), // Add this line,
                        Repeater::make('body')
                            ->schema([
                                Select::make('language_id')
                                    ->searchable()
                                    ->preload()
                                    ->relationship(name: 'language', titleAttribute: 'name'),
                                TextInput::make('text')->required(),
                            ])
                            ->addActionLabel('Add Another Language For Body')
                            ->columns(2)
                            ->rules([new EnglishTranslationMustExist()]), // Add this line,

                    ]),
            ]);
    }

However it works on save but then when i update say the title of one of the language codes it tries to updated a language_id
update
  `fcm_notification_templates`
set
  `body` = [ { "language_id": "163",
  "text": "thai bodys" },
  { "language_id": "43",
  "text": "english body" } ],
  `language_id` = 43,
  `fcm_notification_templates`.`updated_at` = 2024 -02 -09 17: 09: 25
where
  `id` = 3

Not sure why its thinking language_id is its own column
Was this page helpful?