Laravel雄辩的多重has和where子句 [英] Laravel eloquent multiple has and where clause

查看:83
本文介绍了Laravel雄辩的多重has和where子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Employee::has("tags")->orHas("Categories")->where("employeeName","LIKE","seo%")->get();

我有两个belongsToMany关系,分别是标签和类别. 除非我在后面放置where子句,否则Mutiple has子句会起作用.

I have two belongsToMany relationship which is tags and Categories. Mutiple has clause works unless I put where clause after.

如何在has子句中使用???

How can I use has clause with where ??

我需要帮助!

推荐答案

您可能想要这样的东西:

You probably want something like this:

Employee::where(function($q) {
  $q->has("tags")->orHas("Categories");
})->where("employeeName","LIKE","seo%")->get();

因为您需要在查询中使用方括号才能获得期望的结果

because you need to have brackets in your query to get what you expect

这篇关于Laravel雄辩的多重has和where子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆