0

我有 2 张桌子 - 问题和回答。我想为响应表(调查系统)中给出的每个答案插入 question_ids。我已经能够在响应表中插入答案,但不能插入相应的 question_ids。这是我的控制器。

public function store(Request $request)
{
 for($i=1; $i<=count($request->answer); $i++)
 {
   $answers[] = [
    'answer' => $request->answer[$i],
    'question_id' => $request->question_id];
 }
 Response::insert($answers);
}

// 看法

<div class="form">
            <div id="successmessage">Survey sent successful. Thank you!</div>
            <div id="errormessage">Errors</div>
            <form action="{{ route('surveys.store') }}" method="post" role="form" class="surveyForm">
                @csrf
                <?php
                ;$count=1;
                ?>
                @foreach($survey->questions as $question)
                @switch($question->input_type)
                @case('text')
                @case('email')
                <div class="form-group">
                    <input type="{{$question->input_type}}" name="answer[{{$count}}]" class="form-control"
                        id="{{strtolower($question->qtn)}}" placeholder="{{$question->qtn}}"
                        data-rule="{{$question->data_rule}}" data-msg="{{$question->data_message}}" />
                    <div class="validation"></div>
                </div>
                @break
                @case('textarea')
                <div class="form-group">
                    <textarea class="form-control" name="answer[{{$count}}]" rows="5" data-rule="{{$question->data_rule}}" data-msg="{{$question->data_message}}" placeholder="{{$question->qtn}}"></textarea>
                    <div class="validation"></div>
                </div>
                @break
                @endswitch
                <?php $count++; ?>
                @endforeach
                <div class="text-center">
                    <button type="submit">Send</button>
                </div>
            </form>
        </div>
4

0 回答 0