V
V
Voll.2016-08-19 16:09:09
HTTP Cookies
Voll., 2016-08-19 16:09:09

How to save shopping map in laravel cookies?

An unregistered user adds an item to the cart. Sessions are stored in Cookies - rearranged in the config.
The question is how to correctly read and write data,
I threw it in but it did not work.

public function addProduct($productId){
if (array_has(Session::get('cart.items'),$productId))
            return Session::get('cart.items');

        Session::push('cart.items',$productId);
        return Session::get('cart.items');
}

Interested in the optimal storage of not only products, but also the quantity of products, next to the products themselves.
I will be grateful for any help

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
WQP, 2016-08-19
@WQP

I did this: The recording was in js, and the reading was in php.
Stored ID and amount in json

A
Andrzej Wielski, 2016-08-20
@wielski

If the goal is to do it quickly and efficiently, with your experience, you should not write this functionality from scratch.
There are a bunch of ready-made basket packages. My Favorites:
https://github.com/darryldecode/laravelshoppingcart
https://github.com/Crinsane/LaravelShoppingcart

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question