Laravel - Form Input - Multiple select for a one to many relationship

后端 未结 7 735
情深已故
情深已故 2021-02-01 04:40

One of the requirements in an application that I am building is for a form input which takes in a varying number of items for a single field. For instance, sports that I play ar

相关标签:
7条回答
  • 2021-02-01 04:56

    Just single if conditions

    <select name="category_type[]" id="category_type" class="select2 m-b-10 select2-multiple" style="width: 100%" multiple="multiple" data-placeholder="Choose" tooltip="Select Category Type">
     @foreach ($categoryTypes as $categoryType)
      <option value="{{ $categoryType->id }}"
        **@if(in_array($categoryType->id,
         request()->get('category_type')??[]))selected="selected"
        @endif**>
         {{ ucfirst($categoryType->title) }}</option>
         @endforeach
     </select>
    
    0 讨论(0)
提交回复
热议问题