Laravel5 构造器高级查询条件写法

 1 <?php
 2 
 3 #DB 高级查询
 4 // select * from table where A and B or C
 5 $all_data = DB::table("shopnc_goods_common")
 6     ->where("base_goods_commonid", -1)
 7     ->where('goods_name', 'like', '%' . $keywords . '%')
 8     ->orWhere('goods_jingle', 'like', '%' . $keywords . '%')
 9     ->select("goods_commonid")->get();
10 // select * from table A and B
11 $users = DB::table('users')
12     ->whereColumn([
13         ['first_name', '=', 'last_name'],
14         ['updated_at', '>', 'created_at']
15     ])->get();
16 
17 // select * from table A and ( B or C )
18 $all_data = DB::table("shopnc_goods_common")
19     ->where("base_goods_commonid", -1)
20     ->where(function ($query) use ($keywords) {  //闭包
21         $query->where('goods_name', 'like', '%' . $keywords . '%')
22             ->orWhere('goods_jingle', 'like', '%' . $keywords . '%');
23     })
24     ->select("goods_commonid")->get();

 

转载于:https://www.cnblogs.com/helingfeng/p/6486872.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值