Laravel 5.1查询有不受欢迎的“限制1”

时间:2017-07-03 11:32:23

标签: php laravel laravel-5

这在我之前从未发生过

return $this->model->newQuery()
    ->where('canonical', true)
    ->groupBy('systemUrl')
    ->having('n', '>', 1)
    ->select('systemUrl', \DB::raw('count(*) as n'))
    ->pluck('systemUrl')->toArray();

此代码生成所需的查询,但输出意外的limit 1

这怎么可能?

1 个答案:

答案 0 :(得分:3)

问题是缺少get()

return $this->model->newQuery()
    ->where('canonical', true)
    ->groupBy('systemUrl')
    ->having('n', '>', 1)
    ->select('systemUrl', \DB::raw('count(*) as n'))
    ->get() // <--- this one
    ->pluck('systemUrl')->toArray();