title: inserting array to DB in laravel form
body: <p>I'm trying to insert array to DB ( double rows with the same FK (product_id) ) , which i have parent table(Products) and child table(Product_translation) .
  I have 2 Model with relationship and getting the lastinserted Id of the product table , but the issue with me now is it's save word(array) to DB , instead of loop on this array to insert it correclty using laravel form : and here's my form </p>
  
  <pre><code> {!!Form::text('title[]'," ",["class"=&gt;"form-control col-md-7 col-xs-12" )!!} 
  
   {!!Form::text('language[]'," ",["class"=&gt;"form-control col-md-7 col-xs-12" ])!!} 
  
    {!!Form::text('title[]'," ",["class"=&gt;"form-control col-md-7 col-xs-12" )!!} 
  
    {!!Form::text('language[]'," ",["class"=&gt;"form-control col-md-7 col-xs-12" )!!} 
  </code></pre>
  
  <p>and the controller function here's :</p>
  
  <pre><code>  function store( ){
              $parentproduct = new Product();
              $parentproduct-&gt;id = Input::get('id');
              $parentproduct-&gt;save();
              $insertedId = $parentproduct-&gt;id;
              $langArray = Input::get('language');
              $titleArray = Input::get('title');
               $count = count($titleArray);
              for($i = 0; $i &lt; $count; $i++)
  
          { 
  
          $product = new ProductsTranslation(array('language' =&gt; $langArray[$i], 'title' =&gt; $titleArray[$i],
          $product-&gt;product_id = $insertedId));
          $product-&gt;save();
          }
              DB::table('products_translations')-&gt;insert($product);
          }
  </code></pre>
  
  <p>But I'm getting this error: </p>
  
  <blockquote>
    <p>Creating default object from empty value</p>
  </blockquote>
  
  <p>Which is referring to that line : </p>
  
  <h2>    $product->product_id = $insertedId</h2>
  
  <p>Updated now i have a problem to  store the array to my database : </p>
  
  <p>My form getting me this array :</p>
  
  <pre><code>array:2 [▼
    0 =&gt; array:4 [▼
      "id" =&gt; null
      "product_id" =&gt; 225
      "title" =&gt; "English Title"
      "language" =&gt; "En"
    ]
    1 =&gt; array:4 [▼
      "id" =&gt; null
      "product_id" =&gt; 225
      "title" =&gt; "Arabic title"
      "language" =&gt; "Ar"
    ]
  ]
  </code></pre>
  
  <p>And i need to save this to database but it didn't !</p>
  
  <p>which i'm using this code at the controller :</p>
  
  <pre><code>function store(Request $request) {
      $parentproduct = new Product();
      $parentproduct-&gt;id = Input::get('id');
      $parentproduct-&gt;save();
      $insertedId = $parentproduct-&gt;id;
  
       foreach ($request-&gt;input('language') as $i=&gt;$language) {
  
           $insertprod[] = array(
          'id' =&gt;$request-&gt;input('id')[$i], 
         'product_id'=&gt;$parentproduct-&gt;id,
          'title' =&gt;$request-&gt;input('title')[$i],
          'language' =&gt; $request-&gt;input('language')[$i],    
           );
      DB::table('products_translations')-&gt;insert($insertprod); 
  
       }
       ProductsTranslation::insert($insertprod); 
       DB::table('products_translations')-&gt;insert($insertprod);
      // DB::table('products_translations')-&gt;update(['change' =&gt; Input::all()]);
        DB::table('products_translations')-&gt;insert($insertprod);
       //ProductsTranslation::create($insertprod);
        dd($insertprod); 
  
  }
  </code></pre>
  
  <p>When i remove the comment from the line of create</p>
  
  <p>ProductsTranslation::create($insertprod);</p>
  
  <p>It's getting me an error that can't update or insert FK Product_id ! </p>
  
  <p>How can save that array to my db ?</p>