[英]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,
我知道如何在 MySQL 查询中执行此操作,
In MySQL:在 MySQL 中:
SELECT ... WHERE FIND_IN_SET('1', field)
but unable to find the alternative in Laravel.但无法在 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.请尝试以下代码,其中$c是您的搜索 ID,如 1 或 2 或 3 等,而column_name是您的数据库表字段名称,其中搜索 ID 存储如 1、2、3 等。
->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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.