BadMethodCallException

来源:8-4 扩展withCount实现点赞数和评论数

律律律

2019-03-19

Call to undefined method Illuminate\Database\Query\Builder::hsaMany()
// 和用户进行关联

public function zan($user_id)
{
    return $this->hasOne(\App\Zan::class)->where('user_id',$user_id);
}


//文章的所有赞
public function zans()
{
    return $this->hsaMany(\App\Zan::class);
}

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

    $posts->load('user');
    return view("post/index", compact('posts'));

删除 $posts = Post::orderBy(‘created_at’, ‘desc’)->withCount([‘comments’, ‘zans’])->paginate(6);字段里的zans字段就可以运行,但是不显示赞的数量

写回答

2回答

律律律

提问者

2019-03-26

。。。我后面直接复制了源代码的说

0
0

轩脉刃

2019-03-26

hsaMany 细心细心,这里的has和hsa...

0
0

Laravel快速开发简书

Laravel最新特性结合Mysql异步消息队列、ElasticSearch搜索引擎、Debugbar调试利器开发简书

1218 学习 · 613 问题

查看课程