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
Post a Comment