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

learn4u's avatar

Hide attribute API resource

Hello guyz

I have a question please , I'am using api resource to build my api

I have a relation between contact and lead , in the lead resource I have

...
'contact_person' => ContactPerson::make($this->contacts),
...

in the contact , I return everything because I need all the attributes .

I wanted to know how I can hide some attributes only from lead resource ?

Thank you

0 likes
2 replies
learn4u's avatar
learn4u
OP
Best Answer
Level 1

Thank you @d9705996

I found a solution , maybe it will help someone :

public function contacts(){
        return $this->belongsTo('App\ContactPerson' ,  'contact_id')->select(array('id', 'title'));;
    }

Please or to participate in this conversation.