Closed manishlok closed 3 years ago
If you use this fork, check this PR You should be able to do this:
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Models\Product;
use Gloudemans\Shoppingcart\Cart;
use Illuminate\Http\Request;
class CartController extends Controller
{
protected Cart $cart;
public function __construct(Cart $cart)
{
$this->cart = $cart;
}
public function index(Request $request)
{
$cartContent = $this->cart->contentWithRelations(function ($ids) {
return Product::with('image')
->whereIn('id', $ids)
->orderBy('price') // USE ORDER HERE.
->get();
});
return view('cart.index', [
'cart' => $this->cart,
'cartContent' => $cartContent,
]);
}
}
I'll submit a new PR to the original repo covering more tests .
content does return a Collection of CartItem's so you could use reverse or sortBy.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days
Hi there, I am using
$cart = Cart::content( );
to make a collection. How can I show items in Descending order?