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

时间:2019-09-28 05:43:15

标签: php mysql laravel

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

编辑刀片页面

<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>

控制器

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');

1 个答案:

答案 0 :(得分:0)

检查数据库中的类型状态 因为如果在db中输入的是enum或int,则需要将请求强制转换为相同的类型