【发布时间】:2017-05-27 06:14:37
【问题描述】:
我需要检查数据透视表上的两个 where 条件。我知道我可以用这个检查一个条件:
$dis = $user->discounts()->wherePivot('used_for_id', '=', null)
但是,我想要两个 where 条件。当我使用orWherePivot时,两个where条件是ORed在一起,但我希望它们是ANDed在一起。
$whereData = [
['id', "=", $discountId],
['used_for_id', "=", null]
];
【问题讨论】:
-
我喜欢为我的问题添加的唯一一点:在 wherePivot 中的“id”不正确,因为在 where 中有默认的 id。我将其更改为 ->wherePivot('discount_id', $discountId)->wherePivot('used_for_type', null) 并正常工作!
标签: php laravel laravel-5 eloquent laravel-5.1