php - A four digit year could not be found Data missing save condition -
this start_date field format in interview form "yyyy-mm-dd".
the issue can't save when didn't fill start_date field.
here's savehandler code far :
public function savehandler(request $request, $obj) { try { db::begintransaction(); $obj->fill($request->all()); $obj->start_date = isset($interviewtracks['start_date']) ? $interviewtracks['start_date'] : 'yyyy-mm-dd'; if (!$obj->save()) { throw new validationexception($obj->errors()); } foreach($request->interviewtracks $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 = isset($interviewtracks['track_date']) ? $interviewtracks['track_date'] : 'yyyy-mm-dd'; $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 process. please contact system administrator'); } }
any idea ?
you should set start_date
column nullable()
default, if want leave start_date, can leave , eloquent automatically fill null there. use in migrations set nullable...
// example - demo schema::create('users', function (blueprint $table) { $table->increments('id'); $table->string('name'); $table->date('start_date')->nullable(); // <-------- field sets nullable default $table->timestamps(); });
hope helps!
Comments
Post a Comment