lundi 4 février 2019

Transform request object to array for database insert

i have made a duplicable form input using jquery, how do i insert all data

    <tbody id="visites">
    <tr id="ligne">
    <td> <input type... name="id[]"></td>
    <td> <input type... name="date[]"></td>
    <td> <input type... name="statut[]"></td>
    </tr>
    </tbody>
    <script type="text/javascript">
      function dupliquer()
      {
        $( "#ligne" ).clone().appendTo( "#visites" );
      }
    </script>

This is the request bag

        id  
          0 "1"
          1 "1"
          2 "1"
          3 "1"
        date    
          0 null
          1 null
          2 null
          3 null
        statut  
          0 null
          1 null
          2 null
          3 null

The model fillable are

['id','date','statut']

I want to transform the request() bag to something like that

    $data = [
             {id:1,date:'..',statut:'3'},
             {id:1,date:'..',statut:'3'},
             {id:1,date:'..',statut:'3'}
            ]

and perform this :

    foreach($data as ....)
    { 
      Model::create([...]);
    }

I hope i'v been clear ^^ thanks.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire