php - 显示已选中复选框的选中图标(刻度)。| 拉拉维尔 | (复选框,如在 WordPress 中)
问题描述
我想在产品更新页面上显示已选中的图标(勾号)
我想在产品更新页面上勾选已经选择的。如果已选择三星类别,则应在此框中选中。
怎么做?
我使用多对多关系。
在产品模型中,
public function productcategories()
{
return $this->belongsToMany(ProductCategory::class, 'product_category', 'product_id', 'category_id');
}
产品类别模型,
public function products()
{
return $this->belongsToMany(Product::class, 'product_category', 'category_id', 'product_id');
}
在更新视图页面中,
@foreach ($productcategories as $category)
<div class="col-md-12 col-sm-12">
<div class="form-check">
<input class="form-check-input" name="productcategory_id[]" type="checkbox" value="{{$category->id}}">
<label class="form-check-label" for="defaultCheck1">
{{$category->name}}
</label>
</div>
</div>
@foreach ($category->subcategory as $sub)
<div class="col-md-12 col-sm-12 ">
<div class="form-check">
{!! " " !!} {!! " " !!} {!! " " !!}
<input class="form-check-input" name="productcategory_id[]" type="checkbox"
value="{{$sub->id}}">
<label class="form-check-label" for="defaultCheck1">
{{$sub->name}}
</label>
</div>
</div>
@endforeach
@endforeach
解决方案
对于检查和未检查,您应该在您的应用程序和数据库中使用布尔值 false 或 true ...如果为 true,则将进行检查,如果为 false,则不显示选择或在前面检查
推荐阅读
- python - 使用 pyodbc 作为字典列表从 SQL 中检索数据
- c - 如何确定为什么在静态链接期间 LLVM 的 ld.lld 会拉入特定符号
- python - 如何将 numpy 数组放入与 open().read() 相同的字节对象中?
- java - 尝试使用 Spring Boots 的 RestTemplate 使用内容类型 [text/json]
- cakephp - PHP 致命错误:您的 PHP 版本必须等于或高于 5.6.0 才能使用 CakePHP
- java - Spring Cloud Data Flow ignores datasources configured by a spring batch app
- python - 无法获得 tiff 图像分辨率
- r - 如何使用 3 列生成频率数据帧?
- python - 我可以调用 csv.writerow() 中的函数来写入它们的返回值吗?
- javascript - 拒绝处理未触发