3 years ago

Joining 2 tables

Posted 3 years ago by ian_h

Seems a silly question, but can't for the life of me get this working =(

The following SQL query works and is what I'm trying to replicate nicely with hasOne / belongsTo (assuming these are correct)?

$users = \DB::table('table1')
            ->join('table2', 'table1.userid', '=', 'table2.userid')
            ->where('table1.groupid', '=', 2)

        return $users;

There's only ever a single row for 'userid' in both table1 and table2 (hence I thought hasOne()), but alas, I'm stumped!

Any help greatly appreciated! =)



Please sign in or create an account to participate in this conversation.