brazorf
brazorf

Reputation: 1961

Laravel 5.1 query has undesired "limit 1"

This never happened to me before

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

This code produces the desired query, except it output an unexpected limit 1.

How is that possible?

Upvotes: 0

Views: 84

Answers (1)

brazorf
brazorf

Reputation: 1961

Problem was a missing 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();

Upvotes: 3

Related Questions