我如何同时绑定这些查询?

时间:2017-01-05 12:30:28

标签: php laravel subquery

有人可以告诉我如何将这些查询绑定在一个中吗?

$campaign_id = CampaignAdvertising::where('advertising_id', $advert_id) 
                                  ->value('campaign_id'); 

$company_id = Campaign::where('id',$campaign_id)->value('company_id'); 

$admin_id = Admin::where('company_id',$company_id)
                 ->where('id',$user->id) ->get();

2 个答案:

答案 0 :(得分:0)

您可以合并从查询返回的集合,但不能合并查询。您需要使用UNION对原始查询进行组合才能将它们组合起来。

答案 1 :(得分:0)

试试这个

$data = DB::table('campaignadvertising')
->join('campaign', 'campaign.id', '=', 'campaignadvertising.campaign_id')
->join('admin', 'admin.company_id', '=', 'campaign.company_id')  
->select('campaign.*', 'campaignadvertising.*', 'admin.*' )
->where('campaignadvertising.advertising_id', $advert_id)
->where('admin.id',$user->id)
->get();