简体   繁体   中英

How to search in comma separated value in Laravel 5.1?

I want to search in comma separated value from a column in database. I know how to do this in MySQL query,

In MySQL:

SELECT ... WHERE FIND_IN_SET('1', field)

but unable to find the alternative in Laravel.

here is what I have tried so far,

whereRaw(FIND_IN_SET(2,userid))

But it doesn't help.

Please try this:

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

this must help you

Please Try the following code where $c is your search id like 1 or 2 or 3 etc and column_name is the your database table field name where search id store like 1,2,3 etc.

->whereRaw("find_in_set($c , column_name)");

means

->whereRaw("find_in_set('1' , column_name)");
   // Receipt no.
    $fee_type_id = FeeType::select('id')->where('name', 'Main Fee')->first();

    // dd($fee_type_id);
    $receipt_group = FeeReceiptGroup::select('id', 'main_fee_status', 'receipt_group_id')->whereRaw('Find_IN_SET(?, fee_type_id)', [$fee_type_id->id])->first();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM