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

不要在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 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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制