我需要获得基于belongsToMany关系的所有记录的计数。通常,我可以在模型内部的函数中使用groupBy()。但是如果我在模型函数中使用count()或withCount(),我会得到如下错误: 功能代码: public function TaskCount(){
return $this->belongsToManyFatalThrowableError: Call to a member function ad
`user_id`) as `views_count` from `users`但是我需要用独特的IP列来计算这些视图。我无法找到使用自定义列进行计数的任何方法。我可以通过这样的查询函数传递数组:
User::withCount(['views' => function ($q) { // what there?}])->ge