首页 > 解决方案 > 显示已选中复选框的选中图标(刻度)。| 拉拉维尔 | (复选框,如在 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">
                                {!! "&nbsp;" !!} {!! "&nbsp;" !!} {!! "&nbsp;" !!}
                                <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

标签: phplaraveleloquentlaravel-6laravel-7

解决方案


对于检查和未检查,您应该在您的应用程序和数据库中使用布尔值 false 或 true ...如果为 true,则将进行检查,如果为 false,则不显示选择或在前面检查


推荐阅读