Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How do I perform a full join given two tables t1 and t2 in laravel eloquent?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
184 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you were using MySQL.

MySQL has no inbuilt support for full outer join.

But you can use the code like this below to achieve that.

$table2 = DB::table('t2')
         ->rightJoin('t1', 't1.id', '=', 't2.t1_id')

$table1 = DB::table('t1')
        ->leftJoin('t2', 't1.id', '=', 't2.t1_id')
        ->unionAll($table1)
        ->get();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...