How to use NOT FIND_IN_SET in Laravel 5.1?

2020-07-26 11:20发布

问题:

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

->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?

回答1:

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')