darryldecode / laravelshoppingcart

Shopping Cart Implementation for Laravel Framework
1.34k stars 440 forks source link

cart not working with rest api #177

Open tariqtraders opened 5 years ago

tariqtraders commented 5 years ago

Hi I am using following code to get all contents in web application and it works fine \Cart::session($sessionKey)->getContent()

but when i use in rest api. it gives the last item added to cart and not all. Can anyone tell me how to implement this cart using api

markdenverPH commented 5 years ago

Sessions are not implemented in api.php route file. Since Cart needs session to store the items, you should use web.php route file.

augustusnaz commented 4 years ago

@tariqtraders If u add \Illuminate\Session\Middleware\StartSession::class to ur api middleware group in App\Http\Kernel.php it should be fine? See this solution.

cinonu commented 4 years ago

@augustusnaz then it will store all order for same user in same cart

dennernavarro commented 4 years ago

You could also store in the front-end a unique session since REST is supposed to be stateless. In this way, you can have non-users and users using your API