I am using a foreach loop to generate a drop down list via bensampo's ENUMS library, but I need to be able to preselect one of them as I have an edit view and I need it to load the option that is in my database.
My select in my edit view:
<select name="type" id="type" class="form-control">
@foreach ($MailMessageTypes as $value =>$label)
<option value="{{$value}}">{{$label}}</option>
@endforeach
</select>
My function edit in my MailMessageController:
return view('MailMessage.edit', [
'MailMessage' => $MailMessage],
["MailMessageTypes" => MailMessageType::toSelectArray()
]);
I tried to use the enum library's getValues() and getKeys() in the controller but that generates (duplicates) for me, since the foreach keeps generating all options. I am using the select2 plugin
Added: I'm using the select2 plugin for the list.