invaders-xx / filament-jsoneditor

MIT License
22 stars 15 forks source link

Using the `$casts` it showing empty #27

Closed khanakia closed 11 months ago

khanakia commented 11 months ago

I have a Mysql json type field $table->json('functions_stack');

When i use the $casts it shows empty but when i remove the $casts it works fines

class TaskJob extends Model
{
    use HasFactory;

    protected $guarded = ['id'];

    protected $casts = [
        'functions_stack' => 'json',
    ];
}

Screenshot 2023-10-12 at 6 51 46 PM

When $casts removed it works

Screenshot 2023-10-12 at 6 52 30 PM

khanakia commented 11 months ago

I got it fixed by using isJson() by using it like below

\InvadersXX\FilamentJsoneditor\Forms\JSONEditor::make('functions_stack')->isJson()
harlamoff commented 9 months ago

In version JSONEditor 3.1 there is a problem with saving the field. (Mysql json)

Screenshot 2023-11-27 at 17 35 14

After making changes:

Screenshot 2023-11-27 at 17 35 45

Code fix it:

            ->dehydrateStateUsing(function ($state) {
                if(is_string($state)){
                    return json_decode($state, true);
                }
                return $state;
            })
hanaexcl commented 9 months ago

In version JSONEditor 3.1 there is a problem with saving the field. (Mysql json)

Screenshot 2023-11-27 at 17 35 14

After making changes: Screenshot 2023-11-27 at 17 35 45

Code fix it:

            ->dehydrateStateUsing(function ($state) {
                if(is_string($state)){
                    return json_decode($state, true);
                }
                return $state;
            })

I have the same issue. filament: v3.0.102 jsoneditor: v3.1

iztok commented 7 months ago

I had the same problem and solved it with https://github.com/invaders-xx/filament-jsoneditor/issues/27#issuecomment-1827958924

I have a JSON columns which has a JSON cast.