当我试图保存新的面试时,我获得了1048列的状态'不能为NULL。我填写了所有字段,当我dd显示我填写的所有数据时
这是我得到的结果:
"driver_id" => "82"
"interviewTracks" => array:1 [▼
0 => array:5 [▼
"id" => ""
"track_date" => "2016-11-11"
"status" => "2"
"outcome" => "1"
"remark" => "ggg"
到目前为止我的保存代码:
public function saveHandler(Request $request, $obj)
{
try {
DB::beginTransaction();
$obj->fill($request->all());
if (!$obj->save()) {
throw new ValidationException($obj->errors());
}
foreach($request->interviewTracks as $interviewTracks) {
if (empty($interviewTracks['id'])) {
$interviewTracks = new InterviewTrack();
}
else {
$interviewTracks = InterviewTrack::find($interviewTracks['id']);
}
$interviewTracks->interview()->associate($obj);
$interviewTracks['interview_id'] = isset($interviewTracks['interview_id']);
$interviewTracks->status = $interviewTracks['status'];
$interviewTracks->track_date = $interviewTracks['track_date'];
$interviewTracks->outcome = $interviewTracks['outcome'];
$interviewTracks->remarks = $interviewTracks['remarks'];
$interviewTracks->save();
};
if (!$interviewTracks->save()) {
throw new ValidationException($interviewTracks->errors());
}
DB::commit();
return $this->sendSuccessResponse($request);
} catch (ValidationException $e) {
DB::rollback();
\Log::error($e->errors);
return $this->sendErrorResponse($request, $e->errors);
} catch (Exception $e) {
DB::rollback();
\Log::error($e->getMessage());
return $this->sendErrorResponse($request,'Unable to process. Please contact system Administrator');
}
}
任何想法?
答案 0 :(得分:1)
你得到的原因
未定义的索引备注错误
是你没有remarks
字段。
更改此行
$interviewTracks->remarks = $interviewTracks['remarks'];
到这个
$interviewTracks->remarks = $interviewTracks['remark'];