title: How to insert a multidimensional array in a database using laravel
body: <p>I am working on a eCommerce app in laravel. I want to save shopping cart values order and order details tables when the customer clicks checkout button. One order has many order details. I can insert order values: <strong>customerid, orderdate,shipdate,orderamount……</strong>
  But as I have mentioned, one order have many orderdetails. This is my order details table:</p>
  
  <pre><code>**Id 
  ordereid
  product_id
  price
  quantity
  price
  amount**
  </code></pre>
  
  <p>Each order have many products as so:</p>
  
  <pre><code>Array ( [productids] =&gt; Array ( [0] =&gt; 6 [1] =&gt; 11 [2] =&gt; 7 [3] =&gt; 1 ) [quantity] =&gt; Array ( [0] =&gt; 2[1]=&gt;1[2]=&gt;3) [price] =&gt; Array ( [0] =&gt; 750.00 [1] =&gt; 456.00 [2] =&gt; 200.00 [3] =&gt; 700.00 ) [amount] =&gt; Array ( [0] =&gt; 1500 [1] =&gt; 456 [2] =&gt; 600 [3] =&gt; 1400 ) )
  </code></pre>
  
  <p>This is what I have done and am getting      Array to string conversion exception</p>
  
  <pre><code>        for($i=0; $i &lt; count($product); $i++)
          {
   $order_details =new Order_detail;  
      $order_details-&gt;order_id = $orders-&gt;id;        
      $order_details-&gt;product_id=$product['product_id'][$i];        
      $order_details-&gt;quantity=$product['quantity'][$i];    
      $order_details-&gt;unit_price=$product['price'][$i];        
      $order_details-&gt;amount=$product[amount][$i];
  
      $order_details-&gt;save();
  
         }
  </code></pre>
  
  <p>I have also tried to wrap each sub-array in foreach loop but only a single raw is inserted in the order details
  For example if the customer order shopping cart has three products, three rows should be inserted into the order details with:</p>
  
  <pre><code>    Id  
      ordered
      productid
      quantity
      price    
     amount
  </code></pre>
  
  <p>Any help.</p>