There are three tables: users, profiles, friend_request
profiles table's column : profile_id, id (foreign key with users) , first_name,last_name
friend_request's table column : request_id, sender_id,to_user_id, request_status
logic : if profile_id exist in either sender_id column or to_user_id of friend_request table with request_status 2 then they are friends.
example : sender_id to_user_id request_status
5 6 2
$request_accept = DB::table('friend_request')->select('profiles.profile_id','profiles.first_name',
'friend_request.request_id')->leftjoin('profiles', function($join)
{
$join->on('friend_request.sender_id' , '=','profiles.profile_id');
$join->orOn('friend_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) use ($my_profile_id)
{
$q->select('profile_id')->from('profiles')->where('profile_id',$my_profile_id);
})->groupby('profiles.profile_id')->get();
wherenotin i snot working.