php - join query in laravel 5.4 -


i have 2 tables 1. user 2. shortlist

now m getting user details in want details user shortlisted me or not. how can these data using join. common fields : user.id == shortlisted or user.id = shortlistedby

currently getting user data query

$users = db::table('user')           ->select('user.name','user.age','user.fathergotra','user.profession','user.city','user.state','user.areyoumanglik','user.dob','user.profilepic','user.id')                          ->where('showprofileonmatrimony','yes')                         ->where('mobile','!=',$request->mobile)                         ->where('isverified',1)                         ->orderby('user.id','desc')                         ->paginate(5); 

try:

$users = db::table('user')->select('user.name','user.age','user.fathergotra','user.profession','user.city','user.state','user.areyoumanglik','user.dob','user.profilepic','user.id','shortlist.isshortlisted isshortlist')                     ->leftjoin('shortlist', 'user.id', 'shortlisted')                     ->leftjoin('shortlist shortlistedby', 'user.id', 'shortlist.shortlistedby')                     ->where('showprofileonmatrimony','yes')                     ->where('mobile','!=',$request->mobile)                     ->where('isverified',1)                     ->orderby('user.id','desc')                     ->paginate(5); 

more info here: https://laravel.com/docs/5.4/queries#joins


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -