duangou2046
2018-08-16 04:45 浏览 80
已采纳

不要在optgroup选项中显示相同的值

Display the value of the database into the optgroup option. if the value of the parsing controller is the same dengan nilai option then option value in html tag it is not displayed

value of the parsing controller

{{$getData->status}}

my view blade

<div class="input-field col s12">
  <select name ="status" class="js-category browser-default" tabindex="-1" style="width: 100%">
    <optgroup label="Status">
      <option value="{{$getData->status}}">{{$getData->status}}</option>
      <option value="Moderasi">Moderasi</option>
      <option value="Approved">Approved</option>
      <option value="Declined">Declined</option>
    </optgroup>
  </select>
</div>

dont display same value into the optgroup option. I newbie with Laravel and that confused me:(

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答 默认 最新

  • 已采纳
    duanji2002 duanji2002 2018-08-16 06:38

    You can use an array to solve this problem, First, you must define an array for your values:

    $array = array('Moderasi','Approved','Declined');
    

    Second, you want a foreach loop and into that, a condition can help you:

    @foreach($array as $value)
       @if($value != $getData->status)
           <option value="{{$value}}">{{$value}}</option>
       @endif
    @endforeach
    

    And the complete code of your section in your blade must like this:

    <div class="input-field col s12">
       <select name ="status" class="js-category browser-default" tabindex="-1" style="width: 100%">
           <optgroup label="Status">
                <option value="{{$getData->status}}">{{$getData->status}}</option>
                @foreach($array as $value)
                    @if($value != $getData->status)
                        <option value="{{$value}}">{{$value}}</option>
                    @endif
                @endforeach
           </optgroup>
        </select>
    </div>
    
    点赞 评论 复制链接分享

相关推荐