title: Cart conditions won't save to table in laravel
body: <p>I have products with and without conditions in my cart, when I add my cart data to <code>orders</code> table all my cart data will save except my products conditions.</p>
  
  <p>dd of <code>my cart</code> data:</p>
  
  <pre><code>CartCollection {#699 ▼
    #items: array:1 [▼
      2 =&gt; ItemCollection {#670 ▼
        #config: array:6 [▶]
        #items: array:6 [▼
          "id" =&gt; 2
          "name" =&gt; "product two"
          "price" =&gt; 50000.0
          "quantity" =&gt; 2
          "attributes" =&gt; ItemAttributeCollection {#671 ▼
            #items: array:1 [▼
              "attr" =&gt; array:2 [▼
                "name" =&gt; "weight"
                "value" =&gt; "2"
              ]
            ]
          }
          "conditions" =&gt; array:1 [▼
            0 =&gt; CartCondition {#672 ▼
              -args: array:4 [▼
                "name" =&gt; "12 inch"
                "value" =&gt; "25000"
                "type" =&gt; "additional"
                "target" =&gt; "item"
              ]
              -parsedRawValue: 25000.0
            }
          ]
        ]
      }
    ]
  }
  </code></pre>
  
  <p>dd of <code>same cart</code> when I try to save in <code>orders</code> table:</p>
  
  <pre><code>Order {#680 ▼
    #fillable: array:16 [▶]
    #events: array:1 [▶]
    #casts: array:1 [▶]
    #connection: "mysql"
    #table: null
    #primaryKey: "id"
    #keyType: "int"
    +incrementing: true
    #with: []
    #withCount: []
    #perPage: 15
    +exists: true
    +wasRecentlyCreated: true
    #attributes: array:15 [▶]
    #original: array:15 [▼
      "product_data" =&gt; "{"2":{"id":2,"name":"product two","price":50000,"quantity":2,"attributes":{"attr":{"name":"weight","value":"2"}},"conditions":[{}]}}"
      "user_id" =&gt; 1
      "ordernu" =&gt; 9358964473
      "address_id" =&gt; "1"
      "orderstatus_id" =&gt; 1
      "quantity" =&gt; 2
      "payment_id" =&gt; null
      "buyer_name" =&gt; "John Doe"
      "note" =&gt; null
      "buyer_email" =&gt; "admin@admin.com"
      "phone" =&gt; "006281200000000"
      "price" =&gt; null
      "updated_at" =&gt; "2018-02-18 13:03:41"
      "created_at" =&gt; "2018-02-18 13:03:41"
      "id" =&gt; 10
    ]
  </code></pre>
  
  <p>As you see my conditions <code>"conditions":[{}]}</code> is empty.</p>
  
  <p>Here is my save function:</p>
  
  <pre><code> //save cart to orders table and remove items from it
      public function checkout(Request $request)
      {
        $cartItems = Cart::getContent();
  
        try {
          $order = new Order();
          $status  = Orderstatus::where('title', 'Witing Payment')-&gt;value('id');
          $qty = Cart::getTotalQuantity();
          $order-&gt;product_data = $cartItems; //save cart data as json
          $order-&gt;user_id = Auth::user()-&gt;id;
          $order-&gt;ordernu = mt_rand(1000000000, 9999999999);
          $order-&gt;address_id = $request-&gt;input('address_id');
          $order-&gt;orderstatus_id = $status;
          $order-&gt;quantity = $qty;
          $order-&gt;payment_id = $request-&gt;input('payment_id');
          $order-&gt;buyer_name = $request-&gt;input('buyer_name');
          $order-&gt;note = $request-&gt;input('note');
          $order-&gt;buyer_email = $request-&gt;input('buyer_email');
          $order-&gt;phone = $request-&gt;input('phone');
          $order-&gt;price = $request-&gt;input('totalPriceInTotal');
          dd(Auth::user()-&gt;orders()-&gt;save($order)); // dd results
          Auth::user()-&gt;orders()-&gt;save($order);
  
          foreach ($cartItems as $item) {
              $product = Product::find($item-&gt;id);
              $product-&gt;decrement('stock', $item-&gt;quantity);
          }
  
        $user = $order-&gt;buyer_email;
        event(new UserOrdered($order));
  
        //Cart::clear(); //clear cart info
        Session::flash('success', 'Thank you. Your order has been received.');
        return redirect()-&gt;route('ordersindex');
        }catch (Exception $e) {
           return response($e-&gt;getMessage(), 400);
        }
      }
  </code></pre>
  
  <p>any idea?</p>
  
  <h1>UPDATE</h1>
  
  <p>this is how i add products in my cart session:</p>
  
  <pre><code>public function addingItem(Request $request, $id)
      {
        //finding product
        $product = Product::findOrFail($id);
        //get product weight
        $weight = $product-&gt;weight;
        //list of discounts
        $discounts = Discount::all();
        //get current time
        $mytime = Carbon::now();
  
        // get product weight in cart
        $weightArray = [
          'attr' =&gt; [
                'name' =&gt; 'weight',
                'value' =&gt; $weight,
          ]
        ];
  
        // add product conditions to cart
        $customAttributes = [];
        if(!empty($request-&gt;attr)){
            foreach($request-&gt;attr as $sub) {
            // find the suboption
                $sub = Suboption::find($sub);
                if (!empty($sub-&gt;id)) {
                    $itemCondition1 = new \Darryldecode\Cart\CartCondition(
                      [
                        'name' =&gt; $sub-&gt;title,
                        'value' =&gt; $sub-&gt;price,
                        'type' =&gt; 'additional',
                        'target' =&gt; 'item',
                      ]
                    );
                    array_push($customAttributes, $itemCondition1);
                }
            }
        }
  
        //adding product and options to cart
        Cart::add(array(
          'id' =&gt; $product-&gt;id,
          'name' =&gt; $product-&gt;title,
          'price' =&gt; $request-&gt;input('harga'),
          'quantity' =&gt; $request-&gt;input('quantity'),
          'attributes' =&gt; $weightArray,
          'conditions' =&gt; $customAttributes,
        ));
        //success message in return
        Session::flash('success', 'This product added to your cart successfully.');
        return redirect()-&gt;back();
      }
  </code></pre>
  
  <h1>UPDATE 2</h1>
  
  <p>Well I've been playing with codes and I came to this code:</p>
  
  <pre><code>public function checkout(Request $request)
      {
        $cartItems = Cart::getContent();
        foreach($cartItems as $item){
            if (is_array($item['conditions'])) {
              foreach($item['conditions'] as $condition){
                $arsd = [
                  'name' =&gt; $condition-&gt;getName(),
                  'value' =&gt; $condition-&gt;getValue(),
                ];
               return $arsd;
              }
          }
        }
  </code></pre>
  
  <p>which is returning this: (what i need)</p>
  
  <p><a href="https://i.stack.imgur.com/oJo2r.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oJo2r.jpg" alt="screen2"></a></p>
  
  <pre><code>    "product_data" =&gt; "{
  
  "16":{"id":16,"name":"new product","price":100000,"quantity":"1","attributes":{"attr":{"name":"weight","value":"56"}},"conditions":[{"args":null},{"args":null}]},
  
  "4":{"id":4,"name":"product four","price":1500000,"quantity":"1","attributes":{"attr":{"name":"weight","value":"45"}},"conditions":[{"args":null}]},
  
  "1":{"id":1,"name":"product one","price":10000000,"quantity":"1","attributes":{"attr":{"name":"weight","value":"1"}},"conditions":[]}
  } ◀"
  </code></pre>
  
  <p>now the issue is how to apply this in my <code>conditions</code> part of my code? when I dd my cart while saving to database (<code>orders</code> table) this is what I get:</p>
  
  <p><a href="https://i.stack.imgur.com/mfIt8.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mfIt8.jpg" alt="screen3"></a></p>
  
  <blockquote>
    <p>Note: products with id 16 &amp; 4 supposed to have conditions and id 1
    doesn't have any condition.</p>
  </blockquote>
  
  <p>Now, anyone there can help with that?</p>
  
  <h1>UPDATE 3</h1>
  
  <p>Well again I played more with codes and now I have conditions in my orders table (with 1 issue)</p>
  
  <pre><code>foreach($cartItems as $item)
        {
            $item-&gt;id; // the Id of the item
            $item-&gt;name; // the name
            if(is_array($item['conditions']) &amp;&amp; !empty($item['conditions'])) {
              foreach($item['conditions'] as $key =&gt; $value)
              {
                $item['conditions'] = [
                      'name' =&gt; $value-&gt;getName(),
                      'value' =&gt; $value-&gt;getValue(),
                  ];
              }
            }
            $item-&gt;price;
            $item-&gt;quantity; // the quantity
            $item-&gt;attributes; // the attributes
        }
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>"product_data" =&gt; "{"4":{"id":4,"name":"product four","price":1500000,"quantity":"1","attributes":{"attr":{"name":"weight","value":"45"}},"conditions":{"name":"12 inch","value":"25000"}}} ◀"
  </code></pre>
  
  <blockquote>
    <p>The issue is I only get 1 condition in my table while my item has 2
    conditions.</p>
  </blockquote>
  
  <p>any idea on that?</p>