所以,我想将一个布尔值存储到数据库,但是它总是存储其默认值(false)。我正在做的是默认使用功能存储
这是我的UserController:
public function store(Request $request)
{
$request->validate([
'name' =>'required',
'email' =>'required',
'is_active' =>'required',
'password' => 'required|string|min:6|max:191|confirmed',
'password_confirmation' => 'required|same:password',
]);
$user = new User;
$user->name = $request->name;
$user->email = $request->email;
$user->password = Hash::make($request->password);
$user->save();
return redirect()->route('users.index')->with('success','Users created successfully');
}
这是我要提交的创建表单:
<form action="{{ route('users.store') }}" method="POST">
@csrf
<div class="col-sm-9 form-left">
<div class="form-group form-box">
<label for="name">Name</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Name">
</div>
<div class="form-group form-box">
<label for="email">Email</label>
<input type="text" class="form-control" id="email" name="email" placeholder="Email">
</div>
<div class="form-group form-box">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" name="password" placeholder="Password">
</div>
<div class="form-group form-box">
<label for="password_confirmation">Password Confirmation</label>
<input type="password" class="form-control" id="password_confirmation" name="password_confirmation" placeholder="Password Confirmation">
</div>
</div>
<div class="col-sm-3 form-right">
<div class="form-group form-box">
<label for="is_active">Status</label>
<div class="radio">
<label><input type="radio" name="is_active" id="is_active" value="0" checked> Not Verified</label>
</div>
<div class="radio">
<label><input type="radio" name="is_active" id="is_active" value="1" > Verified</label>
</div>
</div>
<button type="submit" class="btn btn-default">Save</button>
</div>
</form>
我错过了什么吗?
答案 0 :(得分:4)
您忘记添加此行。因此它会自动保存默认值
@Document
答案 1 :(得分:2)
保存时您错过了is_active列
$user->is_active = $request->is_active;
答案 2 :(得分:0)
您忘记了吗?
$user->is_active = $request->is_active;