I want to first join sub category and subling and it should be sub query for join mastercategory
$users = DB::table('mastercategory')
->join('subcategory', 'mastercategory.idcategory', '=', 'subcategory.idcategory_mastercategory')
->join('subling', 'subcategory.idsubcategory', '=', 'subling.idsubcategory_subcategory')
->select('mastercategory.*', 'subcategory.*','subling.*')
->get();
I want view like this
Mobile and Access.
1. Mobile
a. IPhone
b. Nokia
2. Mobile Cover
I tried above query and model but i getting view like this
Mobile and Access.
1. Mobile
a. IPhone
b. Nokia
Mobile and Access.
2. Mobile Cover
Try out this, I have used joinSub
function instead of join
it might work according to your needs.
$subcategoryWithSubling = DB::table('subcategory')
->join('subling', 'subcategory.idsubcategory', '=',
'subling.idsubcategory_subcategory')
->select('subcategory.*','subling.*');
$users = DB::table('mastercategory')
->joinSub($subcategoryWithSubling, 'subcategory', function($join) {
$join->on('mastercategory.idcategory', '=',
'subcategory.idcategory_mastercategory')
})->get()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.