kidi
411
14
Laravel

Take only specified attributes from collection.

Posted 10 months ago by kidi

Hi!

When i submit the cart with products, i got this. How can I take only the product_id, warehouse_id, price and quantity attribute?

[
   {
      "product_id":3,
      "barcode":"7898720919381",
      "name":"Persevering intangible product",
      "purchase_price":75114,
      "price":120000,
      "quantity":2,
      "stock":101,
      "original_price":140706,
      "warehouses":[
         {
            "id":2,
            "name":"Rakt\u00e1r 1",
            "pivot":{
               "product_id":3,
               "warehouse_id":2,
               "id":6,
               "stock":101
            }
         },
         {
            "id":3,
            "name":"Rakt\u00e1r 2",
            "pivot":{
               "product_id":3,
               "warehouse_id":3,
               "id":7,
               "stock":34
            }
         }
      ],
      "warehouse_id":2,
      "warehouse_name":"Rakt\u00e1r 1"
   },
   {
      "product_id":2,
      "barcode":"8523579431300",
      "name":"Seamless systemic concept",
      "purchase_price":15109,
      "price":20000,
      "quantity":2,
      "stock":10,
      "original_price":100000,
      "warehouses":[
         {
            "id":2,
            "name":"Rakt\u00e1r 1",
            "pivot":{
               "product_id":2,
               "warehouse_id":2,
               "id":5,
               "stock":10
            }
         }
      ],
      "warehouse_id":2,
      "warehouse_name":"Rakt\u00e1r 1"
   },
   {
      "product_id":1,
      "barcode":"0542637751745",
      "name":"Devolved contextually-based methodology",
      "purchase_price":57311,
      "price":237580,
      "quantity":4,
      "stock":300,
      "original_price":237580,
      "warehouses":[
         {
            "id":2,
            "name":"Rakt\u00e1r 1",
            "pivot":{
               "product_id":1,
               "warehouse_id":2,
               "id":3,
               "stock":300
            }
         },
         {
            "id":3,
            "name":"Rakt\u00e1r 2",
            "pivot":{
               "product_id":1,
               "warehouse_id":3,
               "id":2,
               "stock":20
            }
         },
         {
            "id":4,
            "name":"Rakt\u00e1r 3",
            "pivot":{
               "product_id":1,
               "warehouse_id":4,
               "id":1,
               "stock":10
            }
         }
      ],
      "warehouse_id":2,
      "warehouse_name":"Rakt\u00e1r 1"
   }
]

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.