dimanche 29 janvier 2017

Laravel Collection In One To Many Relationships

I have a query like this(A one to many relationships)

Camp is related to Campaign

$camp =Camp::where('campaign_id', $cid)->where('weight','!=',0)->lists('weight','id')->toArray()

That would result long sql queries

 select `weight`, `id` from `camp` where `campaign_id` = '15' and `weight` != '0'


select `weight`, `id` from `camp` where `campaign_id` = '25' and `weight` != '0'


select `weight`, `id` from `camp` where `campaign_id` = '48' and `weight` != '0'

select weight, id from campaign_creatives where campaign_id = '20' and weight != '0'

select `weight`, `id` from `campaign_creatives` where `campaign_id` = '38' and `weight` != '0'


select `weight`, `id` from `campaign_creatives` where `campaign_id` = '23' and `weight` != '0'

How to make this in one query with multiple campaign_id?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire