In my controller I have the following code
$assignents =Assign::whereHas('users', function ($q) {
$q->where('user_id', 3);
})->get();
I would like to have the number 3 be the authenticated user who is logged in. How can I rewrite this code?
You can use the Auth facade to retrieve the authenticated user.
$assignents = Assign::whereHas('users', function ($q) {
$q->where('user_id', Auth::user()->id);
})->get();