##### 多字段匹配同一个值 ``` whereRaw("concat(title,description,content) like '%".$keyword."%'"); ``` ##### 指定字段 分页 ``` ->orderBy('id','desc') ->limit($page_size) ->offset(($page-1)*$page_size) ->select(['id','title','thumb','description','free','tags','defined_tag','aim_type','time_type']) ``` ##### 被关联模型 条件筛选 ``` $data=Channel::with(['channelidentify'=>function($query)use($arr){ return$query->whereIn('identifyId',$arr); }])->where($where)->select('channelName','channelId')->get()->toArray(); ``` ##### 被关联模型 查询指定字段 ~~~ with('channelidentify:identifyId,code,channelId')->where($where)->select('channelName','channelId') ~~~ ##### 表关联查询 ~~~ $field = ['r.name as role_name','r.id as role_id']; return DB::table("ad_manage_role","m") ->join("ad_role as r","m.role_id","=","r.id") ->where("m.manage_id",$manage_id)->select($field)->get(); ~~~ ##### distinc ~~~ DB::table("product_uv","pu")->where($date_where)->distinct()->count('pu.user_id'); ~~~ 注意 distinct() 去重某个字段数据时 需要的where条件 或者 count中指定出来 #### 计算多行数据的和sum ~~~ $field = 'sum(pay_num) as pay_num_total,sum(fail_order) as fail_order_total,sum(success_pay) as success_pay_total'; $data = ChannelRecord::query()->select(DB::raw($field))->first(); ~~~