mysql - Eloquent ORM using WHERE in both inner join tables -


i'm trying results 2 tables need filter kind of information need both tables. have far this:

// list of students in class;  $students = db::table('students') ->join('userinfo', 'students.studentuserid', '=', 'userinfo.userinfouserid') ->select('userinfo.userinfoinfo', 'userinfo.userinfouserid') ->where('students.studentclassid', '=', $cid) ->get();  

this works fine want further filter outcome. way have userinfo columns this:

id | userinfo.userid | userinfo.userinfotype | userinfo.userinfoinfo 2 | 3 | firstname | johnny 3 | 3 | lastname | baker 4 | 3 | phone | 5551234543

i want firstname information. this:

->where('userinfo.userinfotype', '=', 'firstname')

how can run query in eloquent? i'm using laravel.

you can using querybuilder:

$students = db::table('students')     ->join('userinfo', function($join)         {             $join->on('students.studentuserid', '=', 'userinfo.userinfouserid')                 ->oron('userinfo.userinfotype', '=', 'firstname')         })     ->select('userinfo.userinfoinfo', 'userinfo.userinfouserid')     ->where('students.studentclassid', '=', $cid)     ->get();  

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -