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

extjac's avatar

How to transform relationship json response for an API

I would like to transform the relationship json response for an API. Currently, i tried...

#model
return $this->hasMany()->select('parent_id','field1', 'field2', 'etc')

Also tried

#controller
Model::with('relationship:parent_id,field1,field2,etc')->get();

but it is showing the "parent_id" which i dont want to show.

How can i format the relationship to be able to hide and rename fields? I dont want to use the hidden attribute

0 likes
1 reply

Please or to participate in this conversation.