我需要在 Laravel 的逗号分隔列中显示精确数字匹配我的专栏有以下值我尝试选择 notification_to 列的确切数字为 12 而不是 120、128 的记录。 $getallrecords=Notifications::Where('notification_to','like',$userid.'%')->get();
2 回答
MMMHUHU
TA贡献1834条经验 获得超8个赞
用于find_in_set搜索逗号分隔值。
$getallrecords=Notifications::whereRaw("find_in_set('".$userid."',notifications.notification_to)")->get();编辑:正如@Jerodev 关于防止 sql 注入的评论,您也可以像这样使用它。
->whereRaw("FIND_IN_SET(?, notifications.notification_to) > 0", [$userid])返回值大于零,而不是非 NULL。
或者
->whereRaw("FIND_IN_SET(?, notifications.notification_to)", [$userid])
RISEBY
TA贡献1856条经验 获得超5个赞
这应该可以找到精确的字符串匹配。
$data = DB::table("notifications")
->select("*")
->whereRaw("find_in_set(".$userid.",'notification_to')")
->get();- 2 回答
- 0 关注
- 449 浏览
添加回答
举报
0/150
提交
取消
