Laravel select 行有一列包含输入变量

Laravel select rows has a column including the input variable

我有一个名为 $staff_id 的数据变量,我在数据库中有一个通知 table,在 table 中有一个 "can_see" 列,该列包含的数据为一个用逗号分隔的 id 字符串,我想获取包含该字符串的 $staff_id 的行,我想使用 Laravel 查询生成器,我不想使用存储过程。

DB::table('tasks')->where("staff_id in can_see column!!")->get();

你可以试试这个

DB::table('tasks')->whereRaw(DB::raw('find_in_set("'.$staff_id.'", can_see) > 0'))->get();

如果您将值保存为 '6','7','8','9','10',您可以轻松地使用 LIKE 来过滤记录。

DB::table('tasks')->where('order_id', 'LIKE', "%'".$staff_id."'%")->get();