laravel 解决paginate查询多个字段报错的问题

发布时间:2022-04-16 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了laravel 解决paginate查询多个字段报错的问题脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

用laravel 框架想实现一个分页接口,返回数据表中其中一部分字段

$list = DB::table('Booklist_table')->orderBy('create_time','asc')->paginate($size,['id','tITle','author','image'])->toJson();

return json_decode($list,true);

结果运行报错

"SQLstatE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' `title`, `author`, `image`) as aggregate From `booklist_table`' at line 1 (SQL: select count(`id`, `title`, `author`, `image`) as aggregate from `booklist_table`) ◀"

后来经过查询原因将代码改为

$list = DB::table('booklist_table')->select('id','title','author','image')->orderBy('create_time','asc')->paginate($size)->toJson();

结果正确!

以上这篇laravel 解决paginate查询多个字段报错的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本宝典。

脚本宝典总结

以上是脚本宝典为你收集整理的laravel 解决paginate查询多个字段报错的问题全部内容,希望文章能够帮你解决laravel 解决paginate查询多个字段报错的问题所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。