2017-05-02 75 views
0

我正在做一個頁面,我可以用複選框顯示數據列表。那麼我會自動檢查數據庫,如果數據在那裏,複選框將被檢查。我現在想要做的是,讓我們說複選框被自動檢查,並且當我自己取消選中並保存時,它將更新數據庫中的數據。我的編碼如何自動選中和取消選中複選框

例子:

<form action="{{URL::to('/granted/'.$d->id)}}" method="get"> 
    <input name="_token" type="hidden" value="{{ csrf_token() }}"/> 
    @foreach($var as $v) 
    <table style="margin-left:20px;"> 
     <caption>{{$v->module_groupname}}</caption> 
     @foreach($name as $n) 
     <?php if($n->module_groupname == $v->module_groupname){?> 
     <tr><td width="80"><input type="checkbox" name="module_code[]" value="{{ $n->module_code }}" 
     <?php foreach($priv as $p){ 
     if($p->user_id == $d->id){ 
      if($p->module_code == $n->module_code){ 
       echo 'checked="checked"'; 
      } 
     } 
    }?>></td> 
    <td width="150">{{$n->module_groupname}}</td> 
    <td width="200">{{ $n->module_desc}}</td> 
    </tr> <?php } ?> 
@endforeach 
</table> 
<hr> 
@endforeach 
<input type="submit" value="select" class="btn btn-s btn-success"> 
</form> 

我一直勸查找給PLUS聲明甲骨文,但我無法找到

回答

0
<input type="checkbox" @if(compare) checked @endif /> 
0

,我建議你看看這個代碼,並嘗試重新格式化你自己的代碼。 您正在使用刀片,因此無處不在。

<form action="{{URL::to('/granted/'.$d->id)}}" method="get"> 
{{ csrf_field() }} 
@foreach($var as $v) 
    <table style="margin-left:20px;"> 
     <caption>{{$v->module_groupname}}</caption> 
     @foreach($name as $n) 
      @if($n->module_groupname == $v->module_groupname) 
       <tr> 
        <td width="80"><input type="checkbox" name="module_code[]" value="{{ $n->module_code }}" {{ $priv->contains('user_id', $d->id) && $priv->contains('module_code', $n->module_code) ? 'checked' : '' }}></td> 
        <td width="150">{{$n->module_groupname}}</td> 
        <td width="200">{{ $n->module_desc}}</td> 
       </tr> 
      @endif 
     @endforeach 
    </table> 
    <hr> 
@endforeach 
<input type="submit" value="select" class="btn btn-s btn-success"> 

我想你可以使用包含的功能,如果你的$上一個變量是一個模型。

我沒有測試這個代碼,所以試試,如果它工作