1

Im using datatables for displaying data from 3 tables, the problem is if vendor_id in check table is empty,will not display the row and so on So I want to display all data even if the columns that are in relationship with other tables empty

Controller

 $vendorTableName= with(new Vendors())->getTable();
 $categoryTableName= with(new Excategories())->getTable();
 $orders =Checks::select(["checks.*","vendors.vendor_name","excategories.category_name"])->between($start, $end)->join($vendorTableName,$vendorTableName.".vendor_id","=","checks.vendor_id")->join($categoryTableName,$categoryTableName.".category_id","=","checks.category_id");
Mathieu Ferre
  • 4,246
  • 1
  • 14
  • 31

1 Answers1

1

You are using the join() method which translates into SQL inner join if you want to get data even if the other tables are empty you must use the leftJoin method instead.

Also i would suggest you to take a look at the official documenation for joins: docs for eloquent joins

and there is a popular StakOverflow question about the differences in joins: understanding the difference between different joins

knetsi
  • 1,601
  • 1
  • 16
  • 18