Summer Sale! All accounts are 50% off this week.

libertey's avatar

Shoopingcart item get stored first but after redirect it is deleted again

Hello, i'm building an shop for an website. Now i wanna try to store Items into an Cart i'm using that package Crinsane / LaravelShoppingcart or most know it as that gloudemans/shoppingcart. i created an controller where i wanna handle all the cart actions like storing and updating deleting etc.

But now the Problem is when i put one Item inside that cart its getting stored first but after i turn on to redirect back it is always empty, so it seems the session is not been stored.

What i should say aswell we have already an bookingform on that website which also works in combination with that Cart Object. Maybe there is the Problem?

public function add(Request $request, $id)
    {
        $element = ShopElement::where('id', $request->get('element'))->first();

        Cart::instance('test')->add($id, "Product", 1, $request->query('price'), 0,$element->toArray());

// if dd() here the Object is stored inside of Cart::content(), but as soon as the redirect comes its removed

        return redirect()->route('shop');
    }

The code inside the view

@foreach($elements as $element)
        <div>
            <p>{{$element->getTitle()}}</p>
            <form method="post" action="{{route('shop.cart.add', [$element->id, 'element' => $element, 'type' => 'add', 'price' => $element->getSale() ? $element->getSale() : $element->getPrice()])}}">
                @csrf
                <button type="submit">To Basket</button>
            </form>
        </div>
    @endforeach

Maybe some guys no where the Problem cames from, if that thing will not work i just will build an Cart Object on my own.

Any Help is appreciated.

0 likes
1 reply
libertey's avatar
libertey
OP
Best Answer
Level 1

The Problem was on my side not on that package i use a ModuleProvider to load my shop and forgot the 'web' middleware for my frontend routes.

Please or to participate in this conversation.