简体   繁体   中英

How I can bind these queries at the same time?

Could somebody tell me how I can bind these queries in one?

$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();

You can merge the collection returned from queries but can not merge queries.

You will need to right raw queries with UNION to combine them.

Try like this

$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();

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM