justbetter / laravel-pagination-with-havings

Makes it possible to use pagination with havings in queries with Laravel.
MIT License
66 stars 10 forks source link

Doesn't work with "withCount" #10

Closed n-hor closed 3 years ago

n-hor commented 3 years ago

Hello! Laravel 5.8 In this case it does not work.

pays its a hasManyThrough relation.

 $orders->withCount(['pays as pay_sum' => function (Builder $q) {
                        return $q->select(DB::raw('SUM(invoice_pays.sum)'));
                    }])->havingRaw('pay_sum >= `orders`.`amount`');

Column not found: 1054 Unknown column 'orders.amount' in 'having clause'

But of course such a column exists. Everything works well without pagination.

royduin commented 3 years ago

5.8 is EOL, just upgrade and remove this package from your application ;)