0
我有2個表(採訪和interviewtrack)在1形式。爲foreach提供的無效參數()Laravel 5.3
這裏是我的savehandler到目前爲止的代碼:
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 $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 to process. Please contact system Administrator');
}
}
這是我的看法表單代碼:
<?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++; ?>
它拋出提供的foreach錯誤無效的參數()時,我儘量節省。 任何想法?
DD($請求 - >所有())...和檢查結果。 – Sherif
無法獲得intertrack字段值。 –