Laravel获得独特的见解

时间:2019-01-16 20:22:48

标签: php laravel

我在控制器上有以下代码:

$shops = Shop::withCount(['views' => function ($query) {
        $query->distinct('visitor');
}])->get();

我使用以下软件包:https://github.com/cyrildewit/eloquent-viewable 在表视图中,我有列访问者。为什么独特的行不通?

我得到关于结果的查询:

select `shops`.*, (select distinct count(*) from `views` where `shops`.`id` = `views`.`viewable_id` and `views`.`viewable_type` = 'App\Shop') as `views_count` from `shops` where `user_id` = 1 order by `id` asc limit 10 offset 0

为什么distinct不起作用?

我需要获取:count(distinct visitor),但不需要distinct count(*)

0 个答案:

没有答案