laravel insert data in multiple rows and in one loop
<p>I have an issue in laravel with inserting data in multiple rows. I managed to insert the names in the ingredient table but I would like to add 2 other inputs (unit and quantity).</p>

<p>Can I do this without creating two more loops ?</p>

<p>Controller: </p>

<pre><code>public function store() {

   $meal = new Meal;
   $meal-&gt;name = Input::get('name');
   $ingredient_names = Input::get('ingredient_names');
   $meal_ingredients = array();
   foreach($ingredient_names as $ingredient_name)
   {
        $meal_ingredients[] = new Ingredient(array(
            'name'=&gt;$ingredient_name
        ));
   }

    //save  into the DB
    $meal-&gt;save();
    $meal-&gt;ingredients()-&gt;saveMany($meal_ingredients);
}
</code></pre>

<p>create.blade.html:</p>

<pre><code>    &lt;div class="panel-body"&gt;
        {{ Form::open(array('route' =&gt; 'meals.store')) }}
            &lt;div class="form-group"&gt;
                {{ Form::label('name', 'Name') }}
                {{ Form::text('name', null, array('class' =&gt; 'form-control')) }}
            &lt;/div&gt;
            &lt;div class="input_fields_wrap"&gt;
                &lt;input class="form-control" type="text" name="ingredient_names[]"&gt;
                &lt;a class="add_field_button"&gt;Ajouter&lt;/a&gt;
            &lt;/div&gt;


            {{ Form::submit('Valider', array('class' =&gt; 'btn btn-primary')) }}
       {!! Form::close() !!}
    &lt;/div&gt;
</code></pre>

<p>meal.js (just to show you that I am using dynamic fields)</p>

<pre><code>// dynamic fields
var max_fields      = 20; //maximum input boxes allowed
var wrapper         = $(".input_fields_wrap"); //Fields wrapper
var add_button      = $(".add_field_button"); //Add button ID

var x = 1; //initial text box count
$(add_button).click(function(e){ //on add input button click
    e.preventDefault();
    if(x &lt; max_fields){ //max input box allowed
        x++; //text box increment
        $(wrapper).append('&lt;div&gt;&lt;input class="form-control" type="text" name="ingredient_names[]"/&gt;&lt;a href="#" class="remove_field"&gt;Supprimer&lt;/a&gt;&lt;/div&gt;'); //add input box
    }
});

$(wrapper).on("click",".remove_field", function(e){ //user click on remove text
    e.preventDefault(); $(this).parent('div').remove(); x--;
})
</code></pre>