Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I load the gender from the database and make it pre-selected in laravel?

I’m trying to show the user what type of gender they currently have selected. (It’s in dutch, Geslacht = Gender)

Here’s the code:

<div class="row">
  <div class="col-sm">
    <div class="form-group text-muted">                                         
      <label for="name">Geslacht:</label>                                         
      <select class="custom-select">                                             
        <option selected value="{{Auth::user()->geslacht}}">Kies een optie</option>
        <option value="1">Mannelijk</option>                                             
        <option value="2">Vrouwelijk</option>                                             
        <option value="3">Zeg ik liever niet</option>                                         
      </select>
    </div>
  </div>

Text is in dutch

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

If you know how I might fix this please let me know 😉

>Solution :

 <option value="1" @if(Auth::user()->geslacht == 1) selected @endif>Mannelijk</option>
 <option value="2" @if(Auth::user()->geslacht == 2) selected @endif>Vrouwelijk</option>   
 <option value="3" @if(Auth::user()->geslacht == 3) selected @endif>Zeg ik liever niet</option>   

You can check in the option like this and if matched value then you can select it

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading