如何检查静态复选框的值是否与Laravel中数据库中的值相等

如何检查静态复选框的值是否与Laravel中数据库中的值相等,laravel,checkbox,Laravel,Checkbox,我的数据库中有一列名为“收入来源” 这是从我的编辑页面内爆的。 问题是保存记录后,我看到所有复选框都被选中。我知道问题的原因是我没有检查复选框的值是否应该等于数据库中的值的东西 我表单上的复选框不是动态的 勾选所有适用于您的选项: {!!Form::checkbox('source_income[]','employeed',null,['id'=>'employeed']) {!!Form::label('employed','employed') {!!Form::checkbo

我的数据库中有一列名为“收入来源”

这是从我的编辑页面内爆的。

问题是保存记录后,我看到所有复选框都被选中。我知道问题的原因是我没有检查复选框的值是否应该等于数据库中的值的东西

我表单上的复选框不是动态的


勾选所有适用于您的选项:


{!!Form::checkbox('source_income[]','employeed',null,['id'=>'employeed']) {!!Form::label('employed','employed')
{!!Form::checkbox('source_income[]','online seller',null,['id'=>'online seller']) {!!Form::label('online-seller','online-seller')
{!!Form::checkbox('source_income[]','rider',null,['id'=>'rider']) {!!Form::label('骑手','骑手(抓取,拉扎达等)')
{!!Form::checkbox('source_income[]','small business owner',null,['id'=>'small business owner']) {!!Form::label('small-business-owner','small-business-owner')
{!!Form::checkbox('source_income[]','no income',null,['id'=>'no income']) {!!Form::label('no-income','no-income')
{!!Form::checkbox('source_income[]','汇款分配',null,['id'=>'汇款分配']) {!!Form::label('汇款-分配','汇款/分配') {!!$errors->first('source_income','

:message

编辑,BLADE.PHP

公共功能编辑($id,Profile$model)
{
$user\u id=Auth::user()->id;
$user=user::findOrFail($user\u id);
$profile=profile::findOrFail($id);
$profileSourceIncome=explode(“,”,$profile->source\u income);
返回视图('dashboard.profile.edit',compact('model','profile'))
->with('user',$user)
->使用('profileSourceIncome',$profileSourceIncome);
}
我真的在这部分停止了
$profileSourceIncome=explode(“,”,$profile->source\u income)

我的问题是,如果复选框的名称等于
$profileSourceIncome[]
中的任何值,如何显示选中的复选框

提前非常感谢

根据,只需将
true
作为
表单::checkbox(…)
调用中的第三个参数传递,即可返回已选中的复选框

公共功能编辑($id,Profile$model)
{
$user\u id=Auth::user()->id;
$user=user::findOrFail($user\u id);
$profile=profile::findOrFail($id);
//将此数组转换为集合
$profileSourceIncome=collect(分解(“,”,$profile->source_income));
返回视图('dashboard.profile.edit',compact('model','profile'))
->with('user',$user)
->使用('profileSourceIncome',$profileSourceIncome);
} 
然后,在刀片文件中,您可以使用执行以下操作:

Form::checkbox('source_income[]','employed',$profileSourceIncome->contains('employed'),['id'=>'employed']))
表单::复选框('source_income[]','online seller',$profileSourceIncome->contains('online-seller'),['id'=>'online seller']))
表单::复选框('source_income[]','rider',$profileSourceIncome->contains('rider'),['id'=>'rider']))
表单::复选框('source_income[]','small business owner',$profileSourceIncome->contains('small-business-owner'),['id'=>'business owner']))
表单::复选框('source_income[]'、'no income'、$profileSourceIncome->contains('no-income')、['id'=>'no income']))
表单::复选框('source_income[]','Migrations Allocation',$profileSourceIncome->contains('Migrations-Allocation'),['id'=>'Migrations Allocation']))

这太棒了!非常感谢@IGP!!!它工作得很好!