@estev instead of using the QueryBuilder you could use Eloquent, and then take advantage of mutating the data using the data casting :
https://laravel.com/docs/master/eloquent-mutators#array-and-json-casting
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi,
I'm using the query builder to get data from an external database. I get a lot of nest json data (some fields are mysql json), i would like to find a way to automatically decode the json fields into arrays so i can work on them properly.
Output example from query builder :
{ id: 1, production_companies: "[{"id":9993,"logo_path":"\/2Tc1P3Ac8M479naPp1kYT3izLS5.png","name":"DC Entertainment","origin_country":"US"},{"id":174,"logo_path":"\/ky0xOc5OrhzkZ1N6KyUxacfQsCk.png","name":"Warner Bros. Pictures","origin_country":"US"},{"id":429,"logo_path":"\/2Tc1P3Ac8M479naPp1kYT3izLS5.png","name":"DC Comics","origin_country":"US"},{"id":83036,"logo_path":null,"name":"Joint Effort","origin_country":"US"},{"id":79,"logo_path":"\/tpFpsqbleCzEE2p5EgvUq6ozfCA.png","name":"Village Roadshow Pictures","origin_country":"US"},{"id":13240,"logo_path":"\/aTc07YaNHo8WNgkQSnvLmG6w4nW.png","name":"Bron Studios","origin_country":"CA"}]", }
for now i'm using json_decode on each field but sometime the fields are nested and the results are not consistents.
Any hint ?
Thank you.
Please or to participate in this conversation.