I have two 3 tables : users,profiles, friend_request
$my_profile_id variable store the value of user's profile ID
$my_user_id = Auth::user()->id;
$my_profile_id = DB::table('profiles')->select('profiles.profile_id', 'profiles.id')->leftjoin('users','users.id' ,'=' ,'profiles.id')->where('users.id',$my_user_id)->pluck('profiles.profile_id')->first();
$friend_accept = DB::table('friend_request')->select('profiles.profile_id','profiles.first_name','interest_request.sent_at','interest_request.interest_id')->leftjoin('profiles', function($join){
$join->on('interest_request.sender_id' , '=','profiles.profile_id');
$join->orOn('interest_request.to_user_id' , '=','profiles.profile_id');
})->where('to_user_id',$my_profile_id)->orwhere('sender_id',$my_profile_id)->where('interest_status','2')->whereNotIn('profiles.profile_id', function($q)
{
$q->select('profiles.profile_id')->from('profiles')->where('profiles.profile_id',$my_profile_id);
})->groupby('profiles.profile_id')->get();
$my_profile_id
variable is working fine in where
and orwhere
clause but when I use in whereNotIn
sub query clause it create error: Variable is not defined