Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在带有复选框的窗体中使用旧值或数据库中的值_Php_Laravel - Fatal编程技术网

Php 如何在带有复选框的窗体中使用旧值或数据库中的值

Php 如何在带有复选框的窗体中使用旧值或数据库中的值,php,laravel,Php,Laravel,我希望使用数据库中的值,以便在我编辑数据库中的值时,如果检查了疫苗,它将保持这种状态。我对选择按钮使用了相同的概念,但不知道如何对复选框执行相同的操作 对于选择按钮,我使用了这个 <div class="col-md-6"> <select name="nutrition" class="form-control"> <option value="" disabled>Nutrition</option>

我希望使用数据库中的值,以便在我编辑数据库中的值时,如果检查了疫苗,它将保持这种状态。我对选择按钮使用了相同的概念,但不知道如何对复选框执行相同的操作

对于选择按钮,我使用了这个

<div class="col-md-6">
        <select name="nutrition" class="form-control">
            <option value="" disabled>Nutrition</option>
            <option value="Healthy"  {{ $clinic->nutrition == 'Healthy' ? 'selected' : '' }}>Healthy</option>
            <option value="Not Healthy" {{ $clinic->nutrition == 'Not Healthy' ? 'selected' : '' }}>Not Healthy</option>
        </select>
    </div>

营养
营养=‘健康’?'所选“:”}}>健康
营养==‘不健康’?'所选“:”}}>不健康
我能用什么做这个

  <div class="form-group row pl-5">
            <label for="vaccine1" class="col-md-4 col-form-label text-md-right">Brucellosis</label>
            <div class="col-md-6">
                <input class="form-control" type="checkbox" id="checkbox" name="vaccine1" value="Brucellosis">
            </div>
        </div>
        <div class="form-group row pl-5">
            <label for="vaccine3" class="col-md-4 col-form-label text-md-right">East Cost Fever</label>
            <div class="col-md-6">
                <input class="form-control" type="checkbox" id="checkbox" name="vaccine3" value="East Cost Fever">
            </div>
        </div>

布鲁氏菌病
东部成本热
值==“东部成本热”?”选中“:”}}>
您可以通过选中要与复选框的值匹配的变量来应用相同的逻辑,或者复选框的名称更可取

如果您的陈述为真,只需将复选框设置为
checked
,就像您在下拉列表中所做的那样

    <input class="form-control" type="checkbox" id="checkbox" name="vaccine3" value="East Cost Fever"  {{ $myValues->value== 'East Cost Fever' ? 'checked' : '' }}>