Drop down selection does not update via edit page in Laravel 8

I have a drop down list in my Laravel project that store data in my SQL DB however in my edit page, everything is able to be changed but the drop down menu selection so I am not sure what I am doing wrong here is my code

Controller:

public function update(Request $request, $energykey)
    {
 $energy->softwareversion = $request->input('softwaretype') == "Old" ? "Old System" : "New System";
    }

view:

  <div>
   <select name="softwaretype">
   <option value="">--Select Type--</option>
   <option {{ $energy->softwareversion == 'Old System' ? 'selected':'' }}>Old System</option>
   <option {{ $energy->softwareversion == 'New System' ? 'selected':'' }}>New System</option>
   </select>
   </div>

1 answer

  • answered 2021-04-21 13:02 Ihtisham Khan

    In your controller you have to just get the option value

    public function update(Request $request, $energykey)
    {
      $energy->softwareversion = $request->input('softwaretype');
    }
    

    In your view make these changes so you can get the values in controller

    <div>
      <select name="softwaretype">
        <option value="">--Select Type--</option>
        <option value="Old System" {{ $energy->softwareversion == 'Old System' ? 'selected':'' }}>Old System</option>
        <option value="New System" {{ $energy->softwareversion == 'New System' ? 'selected':'' }}>New System</option>
      </select>
    </div>