鍍金池/ 問答/PHP/ laravel 多字段模糊匹配

laravel 多字段模糊匹配

不多說,上代碼

              $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'] . '%')
               #如何進(jìn)行多字段模糊匹配
               #->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都是需要進(jìn)行模糊匹配的,但where()第一個(gè)參數(shù)不支持'note,latitude...'的寫法,要怎么做才好

回答
編輯回答
墻頭草

1.使用whereRaw('原生mysql做模糊匹配')
2.使用where閉包

2017年2月14日 09:19
編輯回答
久礙你

試試whereRaw:

->whereRaw("concat(`note`,`latitude`,`address`,`start_at`,`end_at`,`price`) like '%".$search['value']."%'")
2017年8月4日 21:03