samedi 26 septembre 2020

why OrderBy is not working in my query Laravel

I am trying to use orderBy in my query, but its not working , $price contain 'asc' and 'desc' value after submitting form, but same value is showing in my blade. After click price (high to low) I want to show Product with high to low prices. Thanks Advance

values coming from blade

    return Listing_property::latest()
        ->when($city, function ($query, $city) {
            return $query->where('city', '=', $city);
        })
        ->when($type, function ($query, $type) {
            return $query->where('property_type', '=', $type);
        })
        ->when($purpose, function ($query, $purpose) {
            return $query->where('purpose_type', '=', $purpose);
        })
        ->when($bedroom, function ($query, $bedroom) {
            return $query->where('bed_room', '=', $bedroom);
        })
        ->when($bathroom, function ($query, $bathroom) {
            return $query->where('bathroom', '=', $bathroom);
        })
        ->when($minprice, function ($query, $minprice) {
            return $query->where('price', '>=', $minprice);
        })
        ->when($maxprice, function ($query, $maxprice) {
            return $query->where('price', '<=', $maxprice);
        })
        ->when($property_size, function ($query, $property_size) {
            return $query->where('property_size', '>=', $property_size);
        })
        ->when($property_area_type, function ($query, $property_area_type) {
            return $query->where('property_area_type', '<=', $property_area_type);
        })
        ->when($price, function ($query, $price) {
            return $query->orderBy('price',$price);
        })
        ->where('add_type', $types)
        ->paginate(3);

}


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Gb3oac
via IFTTT

Aucun commentaire:

Enregistrer un commentaire