根据从数据库中提取的值获取复选框以进行编辑
Getting checkboxes ticked based on the value extracted from database for edit form
我将我的值存储在数据库中,如下所示:
我可以从数据库中获取表单中的所有值以用于编辑目的,因为 follows:But 我无法根据我存储在数据库中的值来勾选复选框,即如果我有我的数据库中的 MBBS 和 BDS,我想在我的编辑表单中勾选 MBBS 和 BDS 复选框。
对于课程列中的单个值,我能够按如下方式实现单刻度:
<div class="form-group">
<label for='degree'>Degree : </label>
<label class="checkbox-inline">
<input type="checkbox" value="MBBS" id="course" name="course"
@if($book->course == "MBBS")
{{"checked" }}
@endif
/>MBBS
</label>
<label class="checkbox-inline">
<input type="checkbox" value="BDS" id="course" name="course"
@if($book->course == "BDS")
{{"checked" }}
@endif
/>BDS
</label>
<label class="checkbox-inline">
<input type="checkbox" value="B.Pharma" id="course" name="course"
@if($book->course == "B.Pharma")
{{"checked" }}
@endif/>B.Pharma
</label>
</div>
如何访问编辑表单复选框中的值?
您的课程似乎有逗号分隔值,因此您需要将其分解并交叉检查。
试试这个来匹配
@if(in_array("MBBS", explode(",", $book->course)))
{{"checked" }}
@endif
我将我的值存储在数据库中,如下所示:
我可以从数据库中获取表单中的所有值以用于编辑目的,因为 follows:But 我无法根据我存储在数据库中的值来勾选复选框,即如果我有我的数据库中的 MBBS 和 BDS,我想在我的编辑表单中勾选 MBBS 和 BDS 复选框。
对于课程列中的单个值,我能够按如下方式实现单刻度:
<div class="form-group">
<label for='degree'>Degree : </label>
<label class="checkbox-inline">
<input type="checkbox" value="MBBS" id="course" name="course"
@if($book->course == "MBBS")
{{"checked" }}
@endif
/>MBBS
</label>
<label class="checkbox-inline">
<input type="checkbox" value="BDS" id="course" name="course"
@if($book->course == "BDS")
{{"checked" }}
@endif
/>BDS
</label>
<label class="checkbox-inline">
<input type="checkbox" value="B.Pharma" id="course" name="course"
@if($book->course == "B.Pharma")
{{"checked" }}
@endif/>B.Pharma
</label>
</div>
如何访问编辑表单复选框中的值?
您的课程似乎有逗号分隔值,因此您需要将其分解并交叉检查。 试试这个来匹配
@if(in_array("MBBS", explode(",", $book->course)))
{{"checked" }}
@endif