How to create shopping cart with Session

minhliem86 posted 4 years ago

Hi everybody, I'm learning about Laravel. When i code shopping cart project, i have a problem with Session:

Table product: id, name, price.

In Controller i have code: $product = Product::find($id); Session::put('cart.'.$id , $product);

So, How to can get all data form above Session. Thank you ! (Sorry about my English).

minhliem86 replied 4 years ago

Can everybody help me, please

zenry replied 4 years ago Solution
Session::push('cart.items', $product);

Session::get('cart.items'); // array


minhliem86 replied 4 years ago

Thank you so much for your help, zenny

larafeed replied 9 months ago

Instead of creating a shopping cart from scratch, I would recommend you to use a package for the cart or ecommerce system. You can easily get an Laravel based ecommerce site on your server by using packages for that. Here is an example:

Sign in to participate in this thread!

We'd like to thank these amazing companies for supporting us