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

devionti's avatar

Only Showing a field to the requested user

Trying to make a field only visible to the requested user For Index Quary for the user its like this it works fine

else{
return $query->where('id', $request->user()->id)
}

Here is the field in User Resource

Text::make(__('Mobile'), 'mobile')
                    ->canSee(function ($request) {
                        return Auth::user()->id == $request->user()->id; })

I also tried

Text::make(__('Mobile'), 'mobile')
->canSeeWhen('id', $request->user()->id),

It doesn't hide at all if the user has view-any-user permission and is viewing another user. Basically everyone can see the mobile field

0 likes
3 replies
devionti's avatar
devionti
OP
Best Answer
Level 2

I should have used $this->id yea it is what I intended. Now everything is peachy.

         Text::make(__('Mobile'), 'mobile')
->canSeeWhen($this->id, $request->user()->id),

Please or to participate in this conversation.