BKWLD / decoy

A Laravel model-based CMS
http://docs.decoy.bukwild.com/
MIT License
303 stars 44 forks source link

Store Model data as json? #81

Open eminos opened 7 years ago

eminos commented 7 years ago

Is there a way to store data for a model as nested json, in one db column?

%fieldset
    .legend Other
    != Former::text('content.section1.heading')
    != Former::text('content.section1.lead')
    != Former::text('content.section2.heading')
    != Former::text('content.section2.lead')

I have a bunch of fields for a model, but not really many enough to qualify for a related model.

eminos commented 7 years ago

I think I figured it out.

%fieldset
    .legend Section 1
    != Former::text('content[section1][heading]')
    != Former::text('content[section1][body]')

And then on the model:

protected $casts = [
    'content' => 'array',
];

Seems to work fine.

Maybe this should be in the docs?