如何在 Laravel 5.1 中使用 NOT FIND_IN_SET?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34244455/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:48:42  来源:igfitidea点击:

How to use NOT FIND_IN_SET in Laravel 5.1?

phplaravellaravel-5eloquentlaravel-5.1

提问by Amrinder Singh

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

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

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

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?

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

回答by jedrzej.kurylo

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()允许您向查询中添加任意 SQL 代码 - 为了反转约束,只需使用您在原始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')