dongshungou7699 2018-01-24 10:59
浏览 86
已采纳

Laravel:whereIn with variable

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.

  • 写回答

2条回答 默认 最新

  • douyunhuan9886 2018-01-24 11:00
    关注

    When you use whereIn() you must pass an array and not string:

    $sections = explode(',', '1,2,3');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题