Support the ongoing development of Laravel.io →
Database Eloquent Views
Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

You could use a presenter class for your model, using the package by shawn ;)

https://github.com/ShawnMcCool/laravel-auto-presenter

Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

In that case, derive your own class from Eloquent and override the getAttributeValue() method to return 'empty' if attribute == ""

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.