【问题标题】:How to write a where condition in laravel query?如何在 laravel 查询中编写 where 条件?
【发布时间】:2021-12-02 15:59:14
【问题描述】:

我写了一个查询,它会像这样在 laravel 中使用 exists() 函数返回真或假

$a=$item->conditions()->exists();

上面的查询工作正常,现在我想用where 条件扩展查询,这将检查status column should equal to the active 的天气,因为我正在编写以下代码,但它会抛出类似Call to a member function where() on boolean 的错误,请帮助我扩展查询以编写 where 条件。

$a=$item->conditions()->exists()->where('status','=','active');

注意:- conditions() -->从模型中返回一个ID

【问题讨论】:

  • 使用$item->conditions()->where('status', 'active')->exists();

标签: laravel laravel-migrations


【解决方案1】:

你必须在调用exists() 方法之前编写 where 条件。 所以它会是这样的:

$a = $item->conditions()->where('status','=','active')->exists();

【讨论】:

  • 我还有一个疑问,它会检查条件表中的 id 和状态 na ,这意味着它不会影响我之前的查询 ryt..?
  • 嗯,我知道你的condition() 中有什么,但你在同一个语句中写了所有条件,所以答案是否定的。它会影响您之前的查询。
猜你喜欢
  • 2021-12-06
  • 2018-08-14
  • 1970-01-01
  • 1970-01-01
  • 2021-09-18
  • 2014-10-04
  • 1970-01-01
  • 2019-07-01
  • 2018-12-24
相关资源
最近更新 更多