dimanche 22 avril 2018

Select Option value does not get stored in database

Laravel view code:

<tbody>
  @foreach($drycleaning as $drycleaning)
      <tr>
        <td class=""><input type="text" size="5" name="dc_"></td>
        <td class="">
            <div><div class="form-group">
            <select id="projectinput5" name="p_dc_" class="form-control">
            <option value="" selected>Price of</option>
            <option name="p_dc_" value="">shirt</option>
            <option name="p_dc_" value="">pant</option>
            <option name="p_dc_" value="">top</option>
            </select>
            </div></div>
        </td>
      </tr>
@endforeach
</tbody>

Controller code:

public function store(Request $request)
{

  $bill = Bill::create([
  'waf_1' => $request->waf_1,
  'dc_1' => $request->dc_1,
  'dc_2' => $request->dc_2,
  'dc_3' => $request->dc_3,
  ...
  'p_dc_1' => $request->p_dc_1,
  'p_dc_2' => $request->p_dc_2,
  'p_dc_3' => $request->p_dc_3,
  ...
  ]);

  $bill->save();
  return redirect()->route('sp.orders.index');
}

Because of the foreach in view, the input and dropdown select is shown 3 times. and only 3 entered input values are successfully saved into a database but not the selected option values. Can anyone help me understand my code mistake?



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

Aucun commentaire:

Enregistrer un commentaire