php - Invalid argument supplied for foreach() Laravel 5.3 -
i have 2 table(interview , interviewtrack) in 1 form.
here's savehandler code 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 $interviewtrack) { \log::info($interviewtrack); if (empty($interviewtrack['id'])) { $interviewtrack = new interviewtrack(); } else { $interviewtrack = interviewtrack::find($interviewtrack['id']); } $interviewtrack->interview()->associate($obj); $interviewtrack['interview_id'] = isset($interviewtrack['interview_id']); $interviewtrack->status = $interviewtrack['status']; $interviewtrack->track_date = isset($interviewtrack['track_date']) ? $interviewtrack['start_time'] : 'yyyy-mm-dd'; $interviewtrack->outcome = $interviewtrack['outcome']; $interviewtrack->remarks = $interviewtrack['remarks']; $interviewtrack->save(); }; if (!$interviewtrack->save()) { throw new validationexception($interviewtrack->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'); } }
here's view form code :
<?php $index = 0; ?> <?php echo form::hidden('interviewtracks['.$index.'][id]', null); ?> <div class="row"> <div class="col-md-4"> <div class="form-group"> <label class="control-label">track date</label> <?php echo form::text('interviewtracks['.$index.'][track_date]', null, ['id' => 'track_date','class' => 'form-control']); ?> </div> </div> <div class="col-md-4"> <div class="form-group"> <label class="control-label">status</label> <?php echo form::select('interviewtracks['.$index.'][status]', $interviewtracklist, null, ['id' => 'status','class' => 'form-control']); ?> </div> </div> <div class="col-md-4"> <div class="form-group"> <label class="control-label">outcome</label> <?php echo form::select('interviewtracks['.$index.'][outcome]', $outcomelist, null, ['id' => 'outcome','class' => 'form-control']); ?> </div> </div> <div class="col-md-12"> <div class="form-group"> <label class="control-label">remark</label> <?php echo form::text('interviewtracks['.$index.'][remark]', null, ['id' => 'remarks','class' => 'form-control']); ?> </div> </div> </div> <?php $index++; ?>
it throws error invalid argument supplied foreach() when try save. idea ??
change:
foreach($request->interviewtracks $interviewtrack)
to:
foreach($request->input('interviewtracks') $interviewtrack)
Comments
Post a Comment