Helllo, i want to do a join between tow tables in laravel, but if table B has no rows query return null. What i want is like this.
table A
id user_id description
1 1 something
2 1 apple
3 2 cherry
table B
user_id post_id vote
(with no records initial)
result table
id user_id description post_id vote
1 1 something null null
2 1 apple null null
3 2 cherry null null
How can i do that? Thank you in advance and I apologize for the worse English.
you should use leftJoin
DB::table("tableA")->leftJoin("tableB","tableA.user_id",'=','tableB.user_id')
->select(["tableA.id as id",'tableA.user_id as user_id','description','post_id','vote'])->get();
Thank you, it was perfect :D