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

VertexBuffer's avatar

How to modify an eloquent column result automatically before response?

Inside my app, I'd say 90% of my models contain image references and at the moment, they are just the filename and extension. E.G my-image.png

However, I want to make it so that on response, instead of just returning; image: 'my-image.png', it actually returns, image: http://mysite.dev/my-image.png.

Obviously I know I can just loop the eloquent response and do it manually, but since I want to do this for a lot of my models, that seems like a pretty repetitive way to do it.

I want to avoid storing the link directly in the database as well in-case a url change happens in the future.

0 likes
2 replies

Please or to participate in this conversation.