Home > Back-end >  Laravel Cart session returns Object instead of Array, How can i convert the object to array
Laravel Cart session returns Object instead of Array, How can i convert the object to array

Time:05-21

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

i am storing array of items in the cart but when retreving the array, its an object

i want to be able to convert the object to arra

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

CodePudding user response:

This may solve your problem;

$request->session()->get('cart')
  • Related