gpt4 book ai didi

eloquent - Laravel 5 Eloquent - where (status = 1 or status = 2)

转载 作者:行者123 更新时间:2023-12-05 08:57:45 27 4
gpt4 key购买 nike

我在 Eloquent 中使用 orWhere 时遇到问题。

我有一个团队,这个团队有一些资料。我想获取状态 = 1 或状态 = 2 的所有配置文件。但我无法让它工作。

我的代码是这样的:

$profile = $this->team->profiles->where('status', 1)->find($id);

谢谢:-)

最佳答案

与其在关系的结果(我假设是一个集合)上调用 where() 你应该在关系对象本身上调用它,你可以通过调用定义的函数来获得它这种关系:

$profile = $this->team->profiles()->whereIn('status', [1,2])->find($id)

我还建议使用 whereIn 而不是两个 where...

关于eloquent - Laravel 5 Eloquent - where (status = 1 or status = 2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29733629/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com