'Laravel orderBy not sorting by product price from max to min

I want to show the products based on the ascending or descending price, but it does not work. So the first product to be displayed is $19, the second $5, the third $10, etc.

public function sort(Category $category)
{
    $products = $category->products()->orderBy('price', 'desc')->get();
    
    return view('products.index', compact('products'));
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source