Laravel的withCount如何实现关联表数量统计?

2026-04-02 04:090阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计176个文字,预计阅读时间需要1分钟。

Laravel的withCount如何实现关联表数量统计?

统计关联数量,单个用法:$posts=Post::withCount('comments')->orderBy('id', 'desc')->paginate(6); 多个用法:$posts=Post::withCount(['comments', 'zans'])->orderBy('id', 'desc')->paginate(6); 调用 $post->comments_count 一定要是5.

统计关联数量,单个用法

$posts = Post::withCount('comments')->orderBy('id','desc')->paginate(6);

多个用法

$posts = Post::withCount(['comments','zans'])->orderBy('id','desc')->paginate(6);

调用

$post->comments_count

一定要是5.3版本之后,5.2和5.1都会报方法未定义

Laravel的withCount如何实现关联表数量统计?

以上这篇laravel withCount 统计关联数量的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易盾网络。

标签:

本文共计176个文字,预计阅读时间需要1分钟。

Laravel的withCount如何实现关联表数量统计?

统计关联数量,单个用法:$posts=Post::withCount('comments')->orderBy('id', 'desc')->paginate(6); 多个用法:$posts=Post::withCount(['comments', 'zans'])->orderBy('id', 'desc')->paginate(6); 调用 $post->comments_count 一定要是5.

统计关联数量,单个用法

$posts = Post::withCount('comments')->orderBy('id','desc')->paginate(6);

多个用法

$posts = Post::withCount(['comments','zans'])->orderBy('id','desc')->paginate(6);

调用

$post->comments_count

一定要是5.3版本之后,5.2和5.1都会报方法未定义

Laravel的withCount如何实现关联表数量统计?

以上这篇laravel withCount 统计关联数量的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易盾网络。

标签: