SebastiaanKloos / filament-code-editor

Code editor for Filament
MIT License
30 stars 18 forks source link

Ability to use ->json() helper on code field to support JSON #3

Open Cannonb4ll opened 2 years ago

Cannonb4ll commented 2 years ago

As per discussed, to be able to load in JSON you'll need to do like this:

  CodeEditor::make('metadata')->afterStateHydrated(function ($state, $set) {
      $set('metadata', json_encode($state));
  })
      ->dehydrateStateUsing(fn ($state) => (array) json_decode($state))
      ->required(),

It would be nice if that could be packed up to:

CodeEditor::make('metadata')->json()