如何在Laravel 5.1中使用NOT FIND_IN_SET? [英] How to use NOT FIND_IN_SET in Laravel 5.1?

查看:1096
本文介绍了如何在Laravel 5.1中使用NOT FIND_IN_SET?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为我们使用FIND_IN_SET在Laravel中搜索逗号分隔的值,如:

As we use FIND_IN_SET to search in comma separated values in Laravel like:

->whereRaw('FIND_IN_SET(2,sent_mail_ids)')

但是现在我想得到那些用逗号分隔的值不存在的结果.为此,我们在MySQL中使用NOT FIND_IN_SET,但是如何在Laravel中使用它?

But now I want to get those results which do not exist in comma separated values. To do this we use NOT FIND_IN_SET in MySQL, but how to use this in Laravel?

推荐答案

whereRaw()允许您向查询中添加任意SQL代码-为了逆转约束,只需使用同一查询您将在原始 SQL 中使用

whereRaw() allows you to add any arbitrary SQL code to your query - in order to reverse the constraint simply use the same query you'd use in raw SQL:

->whereRaw('NOT FIND_IN_SET(2,sent_mail_ids)')

或此约束的另一个变体:

or another variation of this constraint:

->whereRaw('FIND_IN_SET(2,sent_mail_ids) = 0')

这篇关于如何在Laravel 5.1中使用NOT FIND_IN_SET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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