Andrew Vanusi Andrew Vanusi - 29 days ago 8
PHP Question

Laravel 1048 Column cannot be NULL

When I'm trying to save a new interviewTrack I'm getting 1048 Column 'status' cannot be NULL. I've fill all the field, and when I dd it shows all data that I fill

here's the result when I dd it :

"driver_id" => "82"
"interviewTracks" => array:1 [▼
0 => array:5 [▼
"id" => ""
"track_date" => "2016-11-11"
"status" => "2"
"outcome" => "1"
"remark" => "ggg"


here's my save code so far :

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

}


any idea ?

Answer

The reason you are getting

Undefined index remarks error

is that you don't have remarks field.

Change this line

$interviewTracks->remarks = $interviewTracks['remarks'];

to this

$interviewTracks->remarks = $interviewTracks['remark'];