[英]Query and Sub Query Join in laravel
I want to first join sub category and subling and it should be sub query for join mastercategory 我想首先加入子类和subling,它应该是连接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. 试试这个,我使用了
joinSub
函数而不是join
它可能会根据你的需要工作。
$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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.