为了账号安全,请及时绑定邮箱和手机立即绑定

laravel 中逗号分隔列中的精确单词匹配

laravel 中逗号分隔列中的精确单词匹配

PHP
撒科打诨 2022-01-14 16:52:18
我需要在 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])


查看完整回答
反对 回复 2022-01-14
?
RISEBY

TA贡献1856条经验 获得超5个赞

这应该可以找到精确的字符串匹配。

$data = DB::table("notifications")
           ->select("*")
           ->whereRaw("find_in_set(".$userid.",'notification_to')")
           ->get();


查看完整回答
反对 回复 2022-01-14
  • 2 回答
  • 0 关注
  • 449 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号