我想根据 id 运行不同的 ->where() 条件。
例如我正在尝试做的事情:
我已将事件表加入兴趣表,并根据 ID 我想运行不同的 where 条件。
->when('activity.id' <= '214469112', function ($q) {
return $q->where('interests.type', 'regular');
}, function ($q) {
return $q->where('activity.main', 1);
})->get();
但是 ->when() 似乎不尊重 <= => 大于或小于并且总是返回 false 所以 return $q->where('activity.main', 1);
总是被使用。
有什么想法可以根据大于或小于 activity.id 实现不同的 ->where() 条件吗?
最佳答案
唉,有时候人们只是想把问题复杂化。
通过使用做到这一点:
Where('id', '>', int)->where('condition1')->orWhere('id', '<=', int)->where('condition2')->get();
关于Laravel ->when() 大于或小于,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57127911/