Доброго времени суток. Столкнулся с проблемой сортировки в Ларавел.
Есть поле по которому должна проходить сортировка, от большего к меньшему, но почемуто значения на странице идут в разброс вот код выборки
$query->leftJoin("listings","listings.user_id","=","users.id");
$query->whereHas('listings.property', function ($query) {
$query->whereHas('status', function ($query) {
$query
->where('name', 'like', 'sold')
->orWhere('name', 'like', 'rented')
->orWhere('name', 'like', 'past sale');
});
}, '>=', 0);
return $query
->selectRaw('users.*, count(listings.id) AS `listings_count`')
->groupBy("users.id")
->orderBy('listings_count', 'DESC');
string(1414) "select `users`.*, users.*, count(listings.id) AS `listings_count` from `users` left join `listings` on `listings`.`user_id` = `users`.`id` where (exists (select * from `agent_crea` where `agent_crea`.`agent_id` = `users`.`id`) or (`user_type_id` = ? and exists (select * from `images` inner join `user_images` on `images`.`id` = `user_images`.`image_id` where `user_images`.`user_id` = `users`.`id`) and exists (select * from `experiences` where `experiences`.`agent_id` = `users`.`id`) and `title` is not null and `title` != ? and `about` is not null and `about` != ? and `name` is not null and `name` != ? and `license` is not null and `license` != ? and `company` is not null and `company` != ? and `name` is not null and `name` != ? and `agent_since` is not null and `agent_since` != ? and exists (select * from `contacts` where `users`.`contact_id` = `contacts`.`id` and exists (select * from `addresses` where `contacts`.`address_id` = `addresses`.`id` and `address_line` is not null and `phone` is not null)))) and exists (select * from `listings` where `listings`.`user_id` = `users`.`id` and (select count(*) from `properties` where `listings`.`property_id` = `properties`.`id` and exists (select * from `property_statuses` where `properties`.`property_status_id` = `property_statuses`.`id` and (`name` like ? or `name` like ? or `name` like ?))) >= 0) group by `users`.`id` order by `listings_count` desc"