gpt4 book ai didi

mysql - 如何用 Eloquent 方式从单个列和数组中获得不同的结果?

转载 作者:行者123 更新时间:2023-11-29 07:22:01 25 4
gpt4 key购买 nike

我目前有 2 列,一列包含 user_id,另一列包含评级。我希望最终为我的 user_id 提供不同的结果,并为每个不同的 user_id 提供相应的评分数组。

enter image description here

在本例中,我希望最终得到 51、52 ​​和 53 的 3 个数组,其中包含特定 user_id 具有的每个评级记录的评级嵌套数组。

这是可行的还是我只需要获取所有结果并在 php 中计算出来?

最佳答案

我猜你有一个用户表/模型。

// using userRating to reference your table as you didnt give the table/model name
$userRating = User::has("userRating")->with("userRating")->get();

这将为您提供您想要的内容,并且只为您提供具有评级的用户。

关于mysql - 如何用 Eloquent 方式从单个列和数组中获得不同的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35801406/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com