Support the ongoing development of Laravel.io →
Database Eloquent

Hello!

I would like to learn how to integrate custom logic to a model property.

For example, some records of the database table contain an empty value in some column. This empty value means “use default”. I would like to override this empty value with a default one inside Eloquent model.

I.e. when I load such record via Eloquent model, and when I read such property, I would like to get some value instead of an empty string. How is it possible?

And also on write. When I write some value to a model’s property, and this value is equal to some default value, an empty value should be saved to the database.

Thank you!

Last updated 3 years ago.
0
Last updated 3 years ago.
0

Fantastic! Thank you, Chris!

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

plashenkov plashenkov Joined 22 Sep 2014

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.

© 2025 Laravel.io - All rights reserved.