douyinyi7766 2019-08-15 10:23
浏览 38

如何在laravel中的数据透视表上应用groupBy关键字?

I have pivot table users_logs which has many columns and one of them is event_date. I want to retrieve all data which is associated with particular user. I have done it by I can't use groupBy() keyword because it is returning error.

 $GameLogs = User::with(['gamelogs' => function ($query)
{
    $query->where('type', '=', 'play');
    $query->groupBy('event_date');
}])->find(request()->user()->id);

Can someone kindly guide me how can I fix the issue. I would appreciate. Thank you so much.

Error is

SQLSTATE[42000]: Syntax error or access violation: 1055 'o*******_db.g***s.i`
  • 写回答

1条回答 默认 最新

  • dongxiaoying5882 2019-08-15 10:50
    关注

    When you do a groupBy, the selected fields need to be aggregated in strict mode

    $GameLogs = User::with(['gamelogs' => function ($query)
        {
            $query->where('type', '=', 'play');
            $query->groupBy('event_date', 'user_id');
            $query->select('event_date', 'user_id');
        }])
        ->find(request()->user()->id);
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度