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
。。。我后面直接复制了源代码的说
00 -
轩脉刃
2019-03-26
hsaMany 细心细心,这里的has和hsa...
00