dopcpc9207
dopcpc9207
2015-06-06 08:36

laravel查询逗号分隔字符串的位置

已采纳

Using Laravel to check if a value is in an array stored as comma delimited string, example string stored in mysql table 1,14,15,20,25

So I'm trying to add comma's at the start and end to search appropriately

$query = Profile::whereRaw("',' + cf_profile.sub_category_id + ',' LIKE '%,$sub_category->sub_category_id,%'");

Can anyone let me know where I'm going wrong here, as it's returning no results.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • douse8732 douse8732 6年前

    You can use FIND_IN_SET():

    WHERE FIND_IN_SET($sub_category, sub_category_id) > 0
    
    点赞 评论 复制链接分享

相关推荐