我有一个只有两个值的单选按钮表单,admin和operator。
这是刀片
{{-- Level --}}
@if ($errors->any())
<div class="grouped fields {{ $errors->has('level') ? 'input error' : 'success' }}">
@else
<div class="grouped fields">
@endif
{{ Form::label('level', 'LEVEL:') }}
<div class="field">
<div class="ui radio checkbox">
{{ Form::radio('level', 'admin') }}
<label>Administrator</label>
</div>
</div>
<div class="field">
<div class="ui radio checkbox">
{{ Form::radio('level', 'operator') }}
<label>Operator</label>
</div>
</div>
@if ($errors->has('level'))
<div class="ui pointing red basic label">
{{ $errors->first('level') }}
</div>
@endif
</div>
存储控制器
public function store(Request $request)
{
$data = $request->all();
$validasi = Validator::make($data, [
'name' => 'required|max:200',
'email' => 'required|email|max:100|unique:users',
'password' => 'required|confirmed|min:6',
'level' => 'required|in:admin,operator',
]);
if ($validasi->fails()) {
return redirect('dashboards/users/create')
->withInput()
->withErrors($validasi);
}
// hash pass
$data['password'] = bcrypt($data['password']);
User::create($data);
Session::flash('flash_message', 'Data user berhasil disimpan');
return redirect('dashboards/users/index');
}
我不确定刀片或控制器有什么问题。无论我选择什么,单选按钮只会将 admin 传递给数据库
任何线索?