user9155494
user9155494

Reputation:

laravel datatable show data if Eloquent columns empty

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");

Upvotes: 1

Views: 1313

Answers (1)

knetsi
knetsi

Reputation: 1631

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

Upvotes: 1

Related Questions