dtxob80644 2019-06-25 20:11
浏览 207
已采纳

如何在laravel blade.php文件中调用检查所选选项的函数?

I create a fuction for checking selected option and I want to call it in the for the selected part.

@foreach ($stocks as $stock)
   <option value="{{ $stock->id }}" ..... > {{ $stock->name }}</option>
@endforeach

for the .... should be the place to call the function that I created but I don't know how to call it. I tried :

@foreach ($stocks as $stock)
   <option value="{{ $stock->id }}" {{ CheckCombo($stock->id, $product- 
         product_type }} > {{ $stock->name }}</option>
@endforeach

for the function CheckCombo, it returns 'selected' back.

  • 写回答

1条回答 默认 最新

  • doupai6875 2019-06-25 20:26
    关注

    When you loop the option values check it with the db value and if it gets a match echo seleceted

     @foreach ($stocks as $stock)
       <option value="{{ $stock->id }}"  @if( ($stock->id) == ($product-> 
             product_type)) selected @endif > {{ $stock->name }}</option>
    @endforeach
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?