@pablot i guess you can put it inside of your with function.
Apr 1, 2020
2
Level 4
Laravel 5.5 query (sub-query) pluck.
Hi, Please, I have:
Laravel v5.5.48
Tables:
- ads
- ad_settings
- special_sections
table: ads (among others):
- id (9)
- title
table: ad_settings (among others):
- id (45)
- ad_id (9)
- is_active
table: special_sections (among others):
- id (1)
- ad_setting_id (45)
- theme
In my controller I have:
$ad = AdSetting::with(["ad" => function($q){
$q->where('ad_id', '=', 'id');
}])->pluck('ad_id', 'id' );
The above gives me:
Collection {#14946 ▼
#items: array:14 [▼
9 => 45
]
}
dd($ad) gives me the "ad id" (9) and the "ad_setting id" (45)
I'm struggling to pluck the ad_setting id (45) with the ad title. Do I need another (inner) query?
I'm really confused now, can someone please give some advice. Thank you.
Please or to participate in this conversation.