samedi 29 août 2020

Saving Dynamic Select Values in database - Laravel

I am working an multiple select Boxes in a form which are rendered dynamically.

Here in the below scenario I am mapping the selecttion to the parent title.

The example result is { "1": [ 2 ], "2": [ 1, 3 ] }

        <table class="table">
          <thead>
            <tr>
              <td>Variation Name</td>
              <td>Variation Values</td>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td>Size</td>
              <td>
                <select multiple="multiple">
                  <option value="2">Medium</option>
                </select>
              </td>
            </tr>
            <tr>
              <td>Color</td>
              <td>
                <select multiple="multiple">
                  <option value="1">White</option>
                  <option value="3">Blue</option>
                  <option value="4">Black</option>
                </select>
              </td>
            </tr>
          </tbody>
        </table>

I am passing the result to the Laravel Controller so that I could save the response..

I am not sure how do I save the data to the database..

public function itemsStore(Request $request)
    {
        $items_arrays = array($request['itemsArray'], true);
        dd(items_arrays);
    }

The dd result is

array:2 [
  0 => "{"1":[2],"2":[1,3]}"
  1 => true
]

How do I save the values to database in the respective format

item_id | item_value_id
   1             2
   2             1
   2             3


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3jt3Q1Y
via IFTTT

Aucun commentaire:

Enregistrer un commentaire