Laravel 5 eloquent - 其中(状态 = 1 或状态 = 2)
Laravel 5 eloquent - where (status = 1 or status = 2)
我在 eloquent 中使用 orWhere 时遇到问题。
我有一个团队,这个团队有一些个人资料。我想获取状态 = 1 或状态 = 2 的所有配置文件。但我无法让它工作。
我的代码是这样的:
$profile = $this->team->profiles->where('status', 1)->find($id);
谢谢:-)
您可以将 Where In 函数与数组一起使用
$profile = $this->team->profiles->whereIn('status', [1, 2])->get();
而不是调用 where()
关系的结果(我假设它是一个集合)你应该在关系对象本身上调用它,你可以通过调用定义这个关系的函数来获得它:
$profile = $this->team->profiles()->whereIn('status', [1,2])->find($id)
我还建议使用 whereIn
而不是两个 where
...
我在 eloquent 中使用 orWhere 时遇到问题。
我有一个团队,这个团队有一些个人资料。我想获取状态 = 1 或状态 = 2 的所有配置文件。但我无法让它工作。
我的代码是这样的:
$profile = $this->team->profiles->where('status', 1)->find($id);
谢谢:-)
您可以将 Where In 函数与数组一起使用
$profile = $this->team->profiles->whereIn('status', [1, 2])->get();
而不是调用 where()
关系的结果(我假设它是一个集合)你应该在关系对象本身上调用它,你可以通过调用定义这个关系的函数来获得它:
$profile = $this->team->profiles()->whereIn('status', [1,2])->find($id)
我还建议使用 whereIn
而不是两个 where
...