php where多个查询,php – 在laravel查询构建器中使用多个where子句

我在转换以下SQL查询以使用laravels查询构建器时遇到了很多麻烦.

SELECT * FROM gifts

JOIN giftcategory ON gifts.id = giftcategory.giftid

JOIN giftoccasions ON gifts.id = giftoccasions.giftid

JOIN giftrelationship ON gifts.id = giftrelationship.giftid

WHERE (gifts.gender = 'any' OR gifts.gender = 'male')

AND giftoccasions.occasionid = '2'

AND (giftcategory.categoryid = '0' OR giftcategory.categoryid = '1')

AND giftrelationship.relationshipid = '1'

此查询工作正常,但在使用Laravels查询构建器时,我无法获得相同的结果.到目前为止,我有以下代码.它根本不能正常工作.我认为问题可能在于orWhere部分,因为它似乎返回的结果与其他where子句不匹配.

$giftQuery = DB::Table('gifts')

->Join('giftcategory', 'gifts.id', '=', 'giftcategory.giftid')

->Join('giftoccasions', 'gifts.id', '=', 'giftoccasions.giftid')

->where('gifts.gender', '=', "male")

->orwhere('gifts.gender', '=', "any")

->where('giftoccasions.occasionid', '=', "2")

->where('giftoccasions.relationshipid', '=', "1")

->Where('giftcategory.categoryid', '=', "0")

->orWhere('giftcategory.categoryid', '=', "1");

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值