Laravel使用 FIND_IN_SET 匹配字段中的字符串

2023-10-22  本文已影响0人  大萝卜2022

查询type值 == 2和3的数据

$type = 2,3;
 DB::table('article')->whereRaw('FIND_IN_SET(?,type)',[$type])->get();

Article::whereRaw('FIND_IN_SET(?,type)',[$type])->get();

跟据某个特定顺序去排序查出来的数据:FIND_IN_SET

/返回有顺序的客户id
        $customer_ids = $customer->bespeakTime($uid);
        $res = Customer::with('customer_industry', 'zone1', 'zone2', 'department', 'user.agent', 'tag', 'contact', 'source');
        $res->whereIn('id', $customer_ids)
            ->where('is_call', '>=', 0)
            ->orderByRaw(DB::raw("FIND_IN_SET(id, '" . implode(',', $customer_ids) . "'" . ')'));//按照指定顺序排序
上一篇下一篇

猜你喜欢

热点阅读