gpt4 book ai didi

php - 向内连接的 Laravel 添加分页

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

我在分页时遇到错误

$writers = $writer::join('categories','categories.id','=','writers.category_id')
->where([['categories.category_name', '=', $category]])->paginate(1);

谁能告诉我如何对内部联接查询进行分页。

这是我收到的错误消息:

QueryException in Connection.php line 770: SQLSTATE[42000]: Syntax error or access violation: 1140 Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause (SQL: select count(*) as aggregate from writers` inner join categories on categories.id = writers.category_id where (categories.category_name = Comic))

最佳答案

您需要在查询中指定 GROUP_BY 子句

$writers = Writer::join('categories','categories.id','=','writers.category_id')
->where('categories.category_name', '=', $category)
->groupBy('writers.id')
->paginate(1);

更新

如果仍然出现错误,请检查您的config/database.php。确保在 mysql 设置中strict = false

更新2

从 5.7 开始,严格模式适用于 mysql。如果您的 mysql 版本低于 5.7,请设置 strict => false。您可以查看此链接以获取更多信息:

Strict mode

关于php - 向内连接的 Laravel 添加分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41826895/

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