Ad

Laravel Select Rows Has A Column Including The Input Variable

- 1 answer

I have a data variable named $staff_id and I have a notice table in database, in table has a "can_see" column, this column contains data as an id string separated by commas, I want to get the rows has $staff_id of that string, i want to use the Laravel query builder and I don't want to use the Stored procedure.

enter image description here

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

Answer

You can try this

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

If you save your values as '6','7','8','9','10', you could easily use LIKE to filter the records.

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