Laravel雄辩的查询以获取具有指定长度的数组的记录

发布于 2025-02-10 14:16:23 字数 247 浏览 3 评论 0原文

似乎这应该很容易找到答案,但显然不是我的答案。 我需要查询一个记录的数量,该字段称为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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

安静被遗忘 2025-02-17 14:16:23

多亏了此线程 laravel 5.6。 JSONB专栏。数组

我发现适用于我的用例的jsonlength():

$vcount = Variation::where('user_id', user_id)->whereJsonLength('bullets', '=', 5)->count();

thanks to this thread Laravel 5.6. JSONb column. Count array

I found whereJsonLength() that worked for my use case:

$vcount = Variation::where('user_id', user_id)->whereJsonLength('bullets', '=', 5)->count();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文