【发布时间】:2020-11-04 20:16:36
【问题描述】:
问题是在我保存记录后,我看到所有的复选框都被选中了。我知道问题的原因是我没有东西可以检查复选框的值是否应该等于我在数据库中的值。
我的表单上的复选框不是动态的。
<div class="col-md-6 ">
<div class="form-group {{ $errors->has('source_income') ? 'has-error' : ''}}">
<strong>Check all that apply to you:</strong>
<br>
<br>
{!! Form::checkbox('source_income[]', 'employed', null, ['id' => 'employed']) !!}
{!! Form::label('employed', 'Employed') !!}
<br>
{!! Form::checkbox('source_income[]', 'online-seller', null, ['id' => 'online-seller']) !!}
{!! Form::label('online-seller', 'Online Seller') !!}
<br>
{!! Form::checkbox('source_income[]', 'rider', null, ['id' => 'rider']) !!}
{!! Form::label('rider', 'Rider (Grab,Lazada,Etc.)') !!}
<br>
{!! Form::checkbox('source_income[]', 'small-business-owner', null, ['id' => 'small-business-owner']) !!}
{!! Form::label('small-business-owner', 'Small Business Owner') !!}
<br>
{!! Form::checkbox('source_income[]', 'no-income', null, ['id' => 'no-income']) !!}
{!! Form::label('no-income', 'No income') !!}
<br>
{!! Form::checkbox('source_income[]', 'remittances-allotment', null, ['id' => 'remittances-allotment']) !!}
{!! Form::label('remittances-allotment', 'Remittances / Allotment') !!}
{!! $errors->first('source_income', '<p class="help-block">:message</p>') !!}
</div>
</div>
编辑,BLADE.PHP
public function edit($id, Profile $model)
{
$user_id = Auth::user()->id;
$user = User::findOrFail($user_id);
$profile = Profile::findOrFail($id);
$profileSourceIncome = explode(",", $profile->source_income);
return view('dashboard.profile.edit', compact('model','profile'))
->with('user', $user)
->with('profileSourceIncome', $profileSourceIncome);
}
我真的停在这部分$profileSourceIncome = explode(",", $profile->source_income);
我的问题是,如果复选框的名称等于 $profileSourceIncome[] 中的任何值,我如何才能显示选中的复选框?
非常感谢您!
【问题讨论】: