如何在laravel中使用逗号分隔值的列上的``where'' [英] How to use 'where' on column with comma separated values in laravel

查看:50
本文介绍了如何在laravel中使用逗号分隔值的列上的``where''的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在laravel框架中使用php.我想从包含用户ID的表中获取行.这里的问题是用户ID是整数值,并且column(author)包含多个逗号分隔的整数值.这是示例.

I am using php with laravel framework. I want to get rows from table that contains user id. Problem here is that user id is integer value and column(author) contain more than one comma separated integer values. Here is example.

DB::table('stories')->where('author','4')->get();

author列的值:第1行,2、4、5 |第2行:1、3、14 |第3行:4,5我将获得第1行和第3行.所以,请帮助我获得正确的行.

author column have values : row 1: 2,4,5 | row 2: 1,3,14 | row 3 : 4,5 and I will get row 1 and 3. So, Please help me to get right rows.

推荐答案

您可以像这样使用 whereRaw

DB::table('stories')->whereRaw("find_in_set('4',author)")->get();

这篇关于如何在laravel中使用逗号分隔值的列上的``where''的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆