我需要在 Laravel 的逗號(hào)分隔列中顯示精確數(shù)字匹配我的專(zhuān)欄有以下值我嘗試選擇 notification_to 列的確切數(shù)字為 12 而不是 120、128 的記錄。 $getallrecords=Notifications::Where('notification_to','like',$userid.'%')->get();
2 回答

MMMHUHU
TA貢獻(xiàn)1834條經(jīng)驗(yàn) 獲得超8個(gè)贊
用于find_in_set
搜索逗號(hào)分隔值。
$getallrecords=Notifications::whereRaw("find_in_set('".$userid."',notifications.notification_to)")->get();
編輯:正如@Jerodev 關(guān)于防止 sql 注入的評(píng)論,您也可以像這樣使用它。
->whereRaw("FIND_IN_SET(?, notifications.notification_to) > 0", [$userid])
返回值大于零,而不是非 NULL。
或者
->whereRaw("FIND_IN_SET(?, notifications.notification_to)", [$userid])

RISEBY
TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超5個(gè)贊
這應(yīng)該可以找到精確的字符串匹配。
$data = DB::table("notifications") ->select("*") ->whereRaw("find_in_set(".$userid.",'notification_to')") ->get();
- 2 回答
- 0 關(guān)注
- 367 瀏覽
添加回答
舉報(bào)
0/150
提交
取消