BKWLD / decoy

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

Model mutators are ignored in edit forms #76

Closed SomosAMambo closed 7 years ago

SomosAMambo commented 7 years ago

When a attribute has a mutator, like a money field which save in db like 123456.78 but when accessed it should show $ 123,456.78, for example, but in the edit form, it doesn't pass trough the mutator (e.g.: getMoneyAttribute where money is the attribute/field name). And, when saving/creating the model, the mutator/setter (e.g.: setMoneyAttribute) is being ignored as well.

weotch commented 7 years ago

That is by design but I'm open to rethinking it. Here is where this happens:

https://github.com/BKWLD/decoy/blob/master/classes/Models/Base.php#L121-L143

My thinking when adding this was that mutators are added to the model to affect the rendering of data on the public site but the admin should interact with the raw, true data from the database.

But yeah, I'm open to removing it. What do you think?

SomosAMambo commented 7 years ago

I think removing it completely is to radical and can cause unexpected problem on current projects. Maybe a property/param on model basis to switch off this default behavior?

weotch commented 7 years ago

Yeah, like maybe a param that allows you to whitelist some params for either get or set. That sounds good.

SomosAMambo commented 7 years ago

Like this:

     /**
     * Uploadable attributes
     *
     * @var array
     */
    protected $upload_attributes = ['file'];