首页 \ 问答 \ 如何使用Scope在Eloquent ORM中选择除(A和B)之外的所有行?(How to select all rows except (A and B) in Eloquent ORM using Scope?)

如何使用Scope在Eloquent ORM中选择除(A和B)之外的所有行?(How to select all rows except (A and B) in Eloquent ORM using Scope?)

我试图弄清楚如何在Eloquent ORM模式中获得除少数(A和B)之外的所有行。

用户模型

public function notifications()
{
    return $this->hasMany('notification','listener_id','id');
}

型号通知

public function scopeFriendship($query)
{
    return $query->where('object_type', '=', 'Friendship Request');
}

public function scopeSent($query)
{
    return $query->where('verb', '=', 'sent');
}

在这里,除了(友谊和已发送)范围之外,我如何获得用户的所有通知。

Something like:- all rows except !(Friendship AND Sent)

I'm trying to figure out how to get all rows except few (A and B) in Eloquent ORM modal.

User Model

public function notifications()
{
    return $this->hasMany('notification','listener_id','id');
}

Model Notification

public function scopeFriendship($query)
{
    return $query->where('object_type', '=', 'Friendship Request');
}

public function scopeSent($query)
{
    return $query->where('verb', '=', 'sent');
}

Here how can I get all notifications of a user except other than (Friendship and Sent) scope.

Something like:- all rows except !(Friendship AND Sent)

原文:https://stackoverflow.com/questions/27881105
更新时间:2022-04-30 07:04

最满意答案

由于这是8个小时没有回答,让我给你一个粗略(不准确)的答案,你可能想要遵循几个选项:

您可以只使用一个模板并对该模板中的逻辑(要显示的字段/内容)进行编码,而不是您的portlet。 这可能会或可能不是将可维护条件纳入的好点,但在我能想到的所有情况下,我更喜欢这种操作模式。 这样做的好处可能取决于您对所选模板语言的体验以及该环境的强大功能(您使用xsl,velocity还是freemarker?)

如果你的决定不同,一篇文章基本上是一个xml文档 - 所以,给定文章你总是可以得到xml内容并显示/转换它或访问部分(例如xpath)。 你可能想要逃避内容 - 但这取决于你。

另外,正如你所提到的,在6.0.2之前忽略了templateId并且你正在使用6.0 EE:请确保6.0.2早于6.0 EE,所以 - 根据引用的语句 - templateId 被忽略,你应该没问题 ,不需要悲伤。


As this went 8 hours without answer, let me give you a rough (unprecise) answer with a few options that you might want to follow:

You could use just one template and code the logic (what field/content to display) in that template, instead of your portlet. This might or might not be a good point to put maintainable conditions into, but in all scenarios that I can think of, I'd prefer this mode of operation. The ease to do this might depend on your experience with the template language chosen and the power of that environment (do you use xsl, velocity or freemarker?)

If you decide differently, an article is basically an xml document - so, given the article you can always get the xml content and display/transform this or access parts (e.g. xpath). You might want to escape the contents - but that's up to you.

Also, as you mention that templateId is ignored prior to 6.0.2 and you're using 6.0 EE: Be assured that 6.0.2 predates 6.0 EE, so - according to the referenced statement - templateId is not ignored, you should be fine, no need for sadface.

相关问答

更多
  • 转到“站点管理”>“内容”>“文档和媒体”>在那里添加文件,然后从输入中复制URL(当您单击文件时) 指定您正在使用的liferay版本 Go to "site Administration" > "Content" > "Document and Media" > add files there and then copy the url from an input (when you click on an file) specify which liferay version you are usin ...
  • 在查询journalarticles并将structureKey作为值传递时,您需要使用structureId字段 DynamicQuery dynamicQueryStructure = DynamicQueryFactoryUtil.forClass( DDMStructure.class).add(PropertyFactoryUtil.forName("name").like( "%>Empresa%")); ...
  • 我想到的第一个想法是挂钩默认Web内容显示Portlet这将允许您向此portlet添加一些自定义业务逻辑,而不需要实现您从原始portlet中获得的所有内容。 这仍然很大程度上取决于您想要添加的新功能的数量是多少。 正如你所说,你是初学者,所以这里有一些提示,如何启动钩子创建: 访问https://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/liferay-plugin-types-to-develop-with-ma ...
  • 对于Web Content Display portlet,您需要覆盖此jsp: ...\html\portlet\journal_content\view.jsp github: https : //github.com/liferay/liferay-portal/blob/master/portal-web/docroot/html/portlet/journal_content/view.jsp 这里是docu如何覆盖jsp: http://www.liferay.com/documentation ...
  • 它使用JSP,Java(使用Liferay MVCPortlet)可能是一些Alloy UI和Struts 1(因为它在整个Liferay中使用)。 您无法单独下载,但源代码存在于Liferay源存档中。 您只需要挖掘Web内容特定部分。 It's using JSP, Java (using Liferay MVCPortlet) possibly some Alloy UI, and Struts 1 (as it's used throughout Liferay). You can't downlo ...
  • 由于这是8个小时没有回答,让我给你一个粗略(不准确)的答案,你可能想要遵循几个选项: 您可以只使用一个模板并对该模板中的逻辑(要显示的字段/内容)进行编码,而不是您的portlet。 这可能会或可能不是将可维护条件纳入的好点,但在我能想到的所有情况下,我更喜欢这种操作模式。 这样做的好处可能取决于您对所选模板语言的体验以及该环境的强大功能(您使用xsl,velocity还是freemarker?) 如果你的决定不同,一篇文章基本上是一个xml文档 - 所以,给定文章你总是可以得到xml内容并显示/转换它或访 ...
  • 作为解决方法,您可以考虑增加最大队列大小: index.search.writer.max.queue.size=9999999 此外,您可以添加以下内容,使磁盘写入次数减少: lucene.commit.batch.size=10000 lucene.commit.time.interval=300000 您可以考虑参考此缺陷说明以获取更多信息。 干杯! AJ PS这只是一种可能的解决方法或调整方法,但我认为如果上述情况不是,那么某处会有更好的解决方案。 As a workaround of this ...
  • 我猜路径不正确。 authentication.jsp的正确路径是 /portal-web/docroot/html/portlet/portal_settings/authentication.jsp 我检查了源代码,在Liferay 6.1中,没有名为enterprise admin的portlet。 所以请更改文件夹结构。 I guess the path is incorrect. The authentication.jsp's correct path is /portal-web/docroo ...
  • 您可以为此Web内容挂钩此jsp /html/portlet/journal/view-entries.jsp 修改此代码 if (Validator.isNull(orderByCol)) { orderByCol = portalPreferences.getValue(PortletKeys.JOURNAL, "order-by-col", "modified-date"); orderByType = portalPreferences.getValue(PortletKeys.J ...
  • 在liferay中的Document and Media portlet中显示xxx.JSP Document and Media portlet的view.jsp页面位于/ html / portlet / document_library目录中。 您可以使用jsp钩子扩展/覆盖它。 我可以在适当的地方使用 。 这是你如何做到的。 to display xxx.JSP inside the Document and Media ...

相关文章

更多

最新问答

更多
  • python的访问器方法有哪些
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。
  • 响应navi重叠h1和nav上的h1链接不起作用(Responsive navi overlaps h1 and navi links on h1 isn't working)
  • 在C中读取文件:“r”和“a +”标志的不同行为(Reading a File in C: different behavior for “r” and “a+” flags)
  • NFC提供什么样的带宽?(What Kind of Bandwidth does NFC Provide?)
  • 元素上的盒子阴影行为(box-shadow behaviour on elements)
  • Laravel检查是否存在记录(Laravel Checking If a Record Exists)
  • 设置base64图像的大小javascript - angularjs(set size of a base64 image javascript - angularjs)
  • 想学Linux 运维 深圳有哪个培训机构好一点
  • 为什么有时不需要在lambda中捕获一个常量变量?(Why is a const variable sometimes not required to be captured in a lambda?)
  • 在Framework 3.5中使用服务器标签<%=%>设置Visible属性(Set Visible property with server tag <%= %> in Framework 3.5)
  • AdoNetAppender中的log4net连接类型无效(log4net connection type invalid in AdoNetAppender)
  • 错误:发送后无法设置标题。(Error: Can't set headers after they are sent. authentication system)
  • 等待EC2实例重启(Wait for an EC2 instance to reboot)
  • 如何在红宝石中使用正则表达式?(How to do this in regex in ruby?)
  • 使用鼠标在OpenGL GLUT中绘制多边形(Draw a polygon in OpenGL GLUT with mouse)
  • 江民杀毒软件的KSysnon.sys模块是什么东西?
  • 处理器在传递到add_xpath()或add_value()时调用了什么顺序?(What order are processors called when passed into add_xpath() or add_value()?)
  • sp_updatestats是否导致SQL Server 2005中无法访问表?(Does sp_updatestats cause tables to be inaccessible in SQL Server 2005?)
  • 如何创建一个可以与持续运行的服务交互的CLI,类似于MySQL的shell?(How to create a CLI that can interact with a continuously running service, similar to MySQL's shell?)
  • AESGCM解密失败的MAC(AESGCM decryption failing with MAC)
  • SQL查询,其中字段不包含$ x(SQL Query Where Field DOES NOT Contain $x)
  • PerSession与PerCall(PerSession vs. PerCall)
  • C#:有两个构造函数的对象:如何限制哪些属性设置在一起?(C#: Object having two constructors: how to limit which properties are set together?)
  • 平衡一个精灵(Balancing a sprite)
  • n2cms Asp.net在“文件”菜单上给出错误(文件管理器)(n2cms Asp.net give error on Files menu (File Manager))
  • Zurb Foundation 4 - 嵌套网格对齐问题(Zurb Foundation 4 - Nested grid alignment issues)
  • 湖北京山哪里有修平板计算机的