How to use NOT FIND_IN_SET in Laravel 5.1?

12,278

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')
Share:
12,278
Amrinder Singh
Author by

Amrinder Singh

Updated on July 29, 2022

Comments

  • Amrinder Singh
    Amrinder Singh almost 2 years

    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?

  • Mihai
    Mihai over 8 years
    @Insomania Not storing your data in such a way so you dont need find in set is the most correct.But as to the 2 versions above it doesn't matter.
  • Amrinder Singh
    Amrinder Singh over 8 years
    @Mihai, i am sorry i didn't get you
  • Amir Bar
    Amir Bar over 8 years
    @Insomania choose what ever you want, the first one is more readable I think
  • jedrzej.kurylo
    jedrzej.kurylo over 8 years
    I'd go for the first form as it explicitely tells you what the check does - you don't need to care or know what the return value of FIND_IN_SET is