0

I am having trouble the last couple of days figuring this out, i tried googling and every answer I come across doesn't fix my problem

I am storing array of items in the cart but when retrieving the array, it's an object.

I want to be able to convert the object to an array.

Here is my code for storing the array in the cart session

$cart[$id] = [
        "product_id" => $id,
        "name" => $product->product_name,
        "quantity" => $quantity,
        "total" => $total,
    ];

    $request->session()->put('cart', $cart);

but after I get the data from the cart it becomes an object

$cart = $request->session('cart');

I want to either convert this object back to array or retrieve the cart session data as array in the first place

1
  • Are you sure $request->session('cart'); is a valid thing to do? The docs mention either $request->session()->get('cart'); or session('cart') but not this syntax Commented May 21, 2022 at 7:05

1 Answer 1

1

This may solve your problem;

$request->session()->get('cart')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.