V
V
Vitaly2018-11-02 23:04:21
Laravel
Vitaly, 2018-11-02 23:04:21

Sorting in Laravel 5.2?

Good day. Faced a sorting problem in Laravel.
There is a field by which sorting should take place, from larger to smaller, but for some reason the values ​​on the page are scattered here is the selection code

$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"

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question