I'm trying to collect all the records that belong to the sections that happen to them in the variable $sections. But only those from section 1 pick me up. Any suggestions?
$sections = '1,2,3';
$data = News::where('active', '1')
->whereIn('section_id', [$sections])
->get();
If I substitute $sections in the query for the values, this works, but if I use the variable $sections, It doesn't work.
Thanks.
When you use whereIn()
you must pass an array and not string:
$sections = explode(',', '1,2,3');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With