模型查询orm 如何使用FIND_IN_SET

    $site_coupons = SiteCouponMore::query()->where('site_id', $site_id)
     ->with(['coupon.shop','coupon.cash','cloudCoupon','cloudCouponCash'])
     ->whereHas('coupon',function ($query)use($level){
          return $query->where('is_level_limit',2)->orWhere(function ($query)use($level){
          if(empty($level)){
              return $query;
         }else{
              return $query->where('is_level_limit',1)
                ->whereRaw('FIND_IN_SET(1,`level_limit`)');                
         } 
    }); 
})
->whereIn('element_type', [SiteCouponMore::ELEMENT_TYPE_COUPON])
 ->where('status', SiteCouponMore::STATUS_ONLINE)->orderByDesc('sort')
->orderByDesc('id')
 ->forPage($page, $limit)->get();

dd($site_coupons->toArray());

模型查询orm 如何使用FIND_IN_SET
我要查的是level_limit为1的数据,level_limit 是逗号分隔开的string数据。我用的find_in_set
但是并没有管用

这里我该怎么写呢

颠倒的玉石
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
颠倒的玉石
最佳答案

自己解答吧 level_limit和’level_limit’是不一样的`
和’

3年前 评论
讨论数量: 4

where(DB::raw())

DB::raw 原生语句写法

3年前 评论
lddtime 3年前
颠倒的玉石

自己解答吧 level_limit和’level_limit’是不一样的`
和’

3年前 评论

这种我一般都是用正则,想怎么查就怎么查

3年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!