Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ahmedalahmed's avatar

Override any attribute

Suppose I have a model called User and it has 3 attributes name, email, address how to override this attributes by using the concept [ Accessors and mutators ] I mean i don't want to write getNameAttribute() {... }

I need to write getAttribute() { // here i want to add a global info for each attribute or specific ones. }

Thanks for your answers.

0 likes
3 replies
shez1983's avatar

why do you want to override these attributes? need to give more example/your scenario

you could create your own helper function getOverriddenAttribute($attribute) and then do whatever it is you need in there..

ahmedalahmed's avatar

@shez1983 thanks for your response, suppose the following : I want to add a prefix or any global manipulation for all my attributes like add prefix or any other data to any attribute .. so it's not convenient to do it for each attribute separately.

shez1983's avatar

i have given you a solution 2nd para of my prev post.

if this prefix is hardcoded then just name your table column with that prefix.. if you want to do manipulation why would u do the same thing to every field doesnt make sense...

Please or to participate in this conversation.