FilamentF
Filamentβ€’3y ago
Lara Zeus

split json between text field and hint action

this is a sign that I should go to sleep... πŸ™‚

I have a column 'link' cast to array

it's look like this
$link = [
    'url' => 'https....',
    'options' => [
        'color'=>'red',
        'target'=>'_blank',
        //....
    ],
];



so my Input is:

TextInput::make('link.url')
    ->live()
    ->default('https://111')
    ->hintAction(
        Action::make('qr-code-design')
            ->fillForm(function (Get $get) {
                return [
                    'options' => $get('link.options'),
                    'url' => $get('link.url'),
                ];
            })
            ->form([
                Grid::make()
                    ->schema([
                        TextInput::make('url')->default('https://222'),
                        TextInput::make('options.color')->default('#ccdd33'),
                    ])
            ])
            ->action(function (Set $set, $data) {
                $set('link', $data);
            })
            ->color('gray')
            ->icon('heroicon-o-qr-code')
            ->tooltip('customize the QR code design')
            ->iconButton()),


the result after saving to db is

{"url":"https:\/\/11111"}

the options are never saved to db since they not exist in the main component

is there a solution around this?! or better idea
Was this page helpful?