You could make an ItemCreator method that specifically handles these things in some capacity.
https://github.com/ShawnMcCool/StructureExperimentation/blob/master/Domain/Posts/PostCreator.php
Interesting concept. I import the data from an external source, maybe I could set the value when importing, but would prefer if the "(empty)" value would be only visible when outputting and not in database.
You could use a presenter class for your model, using the package by shawn ;)
Still, a good solution, but not general enough. Still have to define every attribute and it's output. Considering I got some amount of columns in the database it isn't exactly what I want.
Maybe you could try implementing model events restoring
and saving
(perhaps in your BaseModel) which would deal with conversion while retrieving and saving records.
http://laravel.com/docs/eloquent#model-events
This way you could adjust "filtering" of model attributes tied to your needs. Plain foreach loop on attributes swapping (empty)
to emptystring and vice-versa would do the job I think.
In that case, derive your own class from Eloquent and override the getAttributeValue() method to return 'empty' if attribute == ""
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community