不多说,上代码
$data = $coupon->with( ['prcture'=>function($query){ $query->select('id','picture_url'); }] ) ->with( ['merchant'=>function($query){ $query->select('id','nickname'); }] ) ->with( ['member'=>function($query){ $query->select('id','nickname'); }] ) ->where( 'id','>=',1 ) ->where("note", 'like', '%' . $search['value'] . '%') #如何进行多字段模糊匹配 #->where("concat(note, ',', latitude, ',',address, ',',start_at,',',end_at, ',',price)", 'like', '%' . $search['value'] . '%') ->select( 'id','note', 'picture_id', 'latitude', 'address', 'cp_id', >>'merchant_id', 'action', 'start_at', 'end_at', 'create_at', 'price', 'status', 'member_id' ) ->paginate( $request->get('length'),null,null,$page )->toArray();
需要匹配的字段比较多,note,latitude,address,start_at,end_at,price都是需要进行模糊匹配的,但where()第一个参数不支持'note,latitude...'的写法,要怎么做才好
1.使用whereRaw('原生mysql做模糊匹配')
2.使用where闭包