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

vibe's avatar
Level 1

Query

I have one problem I want whenever user login one table should show the list of client of his department. how can I pass the user department value to my controller without submitting the request

0 likes
7 replies
mikefolsom's avatar

From inside a controller, you can access the logged-in user via the global helper auth()->user() or the facade Auth::user(). Not sure what you mean by "without submitting the request."

tisuchi's avatar

If I get you correctly, each user belongs to a department. In this case, after logging in a user, get all other users from the same department and show them.

Isn't the technique that you are looking for?

tisuchi's avatar

@vibe

Then it should be easy. Just fetch the logged in user's department and find all the user's who has the same department.

Now show those users to logged in user.

vibe's avatar
Level 1

@tisuchi

my problem is client is one table which has many to many relationship with department and client keeps on changing the department and to serve the client user must get the client who is related to his department

vibe's avatar
vibe
OP
Best Answer
Level 1

@tisuchi

 Thank-you very much for your clue  I got the soultions
$npt= Patient::whereHas('departmetrel', function ($query) { $query->where('department_department_id', '>=', Sentinel::getUser()->depart); })->get();
Collection {#390 ▼
  #items: array:3 [▼
    0 => patient {#391 ▶}
    1 => patient {#373 ▶}
    2 => patient {#392 ▶}
  ]
}
´´´

And i got this answer hope can help others

Please or to participate in this conversation.