Laravel雄辩的查询以获取具有指定长度的数组的记录
似乎这应该很容易找到答案,但显然不是我的答案。 我需要查询一个记录的数量,该字段称为Bullets
包含一个长度为5的数组。这是我目前拥有的,但它正在检查字段本身的字符长度(我相信),不是数组。有人可以帮我吗?
$vcount = Variation::where('user_id', user_id)->whereRaw('LENGTH(bullets) = 5')->count();
It seems like this should be pretty simple to find the answer to but apparently not for me.
I need to query a count of records where the field called bullets
contains an array with a length of 5. Here is what I currently have but it's checking for character length of the field itself(I believe), not of an array. Can anyone help me out please?
$vcount = Variation::where('user_id', user_id)->whereRaw('LENGTH(bullets) = 5')->count();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
多亏了此线程 laravel 5.6。 JSONB专栏。数组
我发现适用于我的用例的jsonlength():
thanks to this thread Laravel 5.6. JSONb column. Count array
I found whereJsonLength() that worked for my use case: