As I could see from the API of that package, you can do Cart::count() which will return the number of items in the cart. So just show the cart if there are more than 0 items in the cart.
Hope that helps.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, this is a theoretical question because i am really struggling with the logic of this. I am building a webshop and i have a shopping Cart, everything is working fine, i can add/show/delete items in my cart. using this package: https://github.com/Crinsane/LaravelShoppingcart
But the items in my cart are not stored in my database. So i assume they are stored in a session. What i want to do is show my shopping cart only for the user who puts them in the cart. (I already have middleware setup so only authenticated users can put or see items in the cart) When using my database i make a relation and i just do Auth::user()->Cart(). But i'm not sure how to tackle it without relationships ? Do i make a model of my shopping cart even though i have no table for it?
edit:
this is my addToCart logic, how should i say i want to assing this to a session from the current user? , because the package probably has some logic in it that stores it in a session.
public function addItem(WinkelMandRequest $request, $id)
{
$product = Product::findOrFail($id);
$aantal = $request->input('aantal');
$formaat = $request->input('formaat_list');
$kleur = $request->input('kleur_list');
Cart::add(array(
'id' => $product->id,
'name' => $product->naam,
'qty' => $aantal,
'price' => $product->prijs,
'options' => array('formaat' => $formaat, 'kleur' => $kleur, 'foto' => $product->foto)
));
return redirect('winkelmand');
}
Please or to participate in this conversation.