gpt4 book ai didi

php - Laravel 组违规

转载 作者:行者123 更新时间:2023-11-29 16:48:19 26 4
gpt4 key购买 nike

我想在 auth 用户的收件箱中获取所有消息以及向他发送消息的人员姓名。

我有疑问

    $user_id=Auth::id();
$messages=Chat::with('user')
->where('user_id',$user_id)
->groupBy('friend_id')
->limit(10)
->get();

但是 Laravel 不肯让我明白这一点,并说:

SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'mojaodeca.chats.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by (SQL: select * from chats where user_id = 1 group by friend_id limit 10)

最佳答案

用这个

 $user_id=Auth::id();
$messages=Chat::with('user',function($q){
$q->groupBy('friend_id')
})
->where('user_id',$user_id)
->limit(10)
->get();

关于php - Laravel 组违规,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52974358/

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