首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用groupBy从mySQL获取数据时出现Laravel错误

使用groupBy从mySQL获取数据时出现Laravel错误
EN

Stack Overflow用户
提问于 2021-02-06 15:56:48
回答 1查看 40关注 0票数 0

我想从只有1个id_product的mySQL中获取数据,所以当有2个数据具有相同的id_product值时。它只得到了第一个。我已经尝试了在mySQL中的查询和它的工作,查询如下

代码语言:javascript
复制
select `product_photo`.*, `product`.`id_merchant` from `product_photo` inner join `product` on 
`product_photo`.`id_product` = `product`.`id` where `product`.`id_merchant` = 11 group by 
`product_photo`.`id_product` 

但是当我在我的laravel控制器上实现它时,我得到了错误,代码是这样的

代码语言:javascript
复制
$id_merchant = $request->input('id_merchant');

    $photo=DB::table('product_photo')
    ->join('product','product_photo.id_product','=','product.id')
    ->select('product_photo.*','product.id_merchant')
    ->where('product.id_merchant','=',$id_merchant)
    ->groupBy('product_photo.id_product')
    ->get();
    
    return response()->json(['success'=>true,'message'=>'success', 'data' => $photo],200);

有没有人能告诉我为什么我的小腹出错了?对不起,我的英语

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-06 16:33:44

这是由MySQL的严格模式引起的。在config/database.php文件中将strict更改为false。

打开文件时,在mysql数组中设置strict => false。禁用MySQL的严格模式后,它应该不会再显示错误。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66074721

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档