gpt4 book ai didi

php - 选项数据未在数据库中更新

转载 作者:行者123 更新时间:2023-11-29 15:36:56 26 4
gpt4 key购买 nike

编辑时,如果我选择另一个选项并单击“保存”按钮,它不会在数据库中更新。

编辑 Blade 页面

<select class="form-control" name="status">
<option value="">Select Status</option>
<option value="0" {{($inspection_schedules->status == '0')? 'selected': ''}}>Scheduled</option>
<option value="1" {{($inspection_schedules->status == '1')? 'selected': ''}}>Inprogress</option>
<option value="2" {{($inspection_schedules->status == '2')? 'selected': ''}}>Completed</option>
</select>

Controller

public function postUpdateInspectionSchedule(Request $request, $id){

$request->validate([
'user_id' => 'required',
'inspection_date' => 'required|date_format:m/d/Y',
]);

$inspection_schedules = InspectionSchedule::findOrFail($id);
$inspection_schedules->user_id = $request->user_id;
$inspection_schedules->inspection_id = $id;
$inspection_schedules->inspection_date = Carbon::createFromFormat('m/d/Y', $request->inspection_date)->format('Y-m-d');
$inspection_schedules->status = $request->status;
$status = $inspection_schedules->save();
if($status == 1){
Session::flash('msg', 'Inspection Updated successfully.');
}else{
Session::flash('msg', 'Something went wrong, Try again later!');
}
return redirect('/admin/inspection/schedule/edit/'.$id);
}

路线

Route::get('/inspection/schedule/edit/{id}', 'InspectionController@getEditInspectionSchedule');
Route::post('/inspection/schedule/edit/{id}', 'InspectionController@postUpdateInspectionSchedule');

最佳答案

检查数据库中的类型状态因为如果数据库类型是 enum 或 int 那么你需要将请求转换为相同类型

关于php - 选项数据未在数据库中更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58143712/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com