Laravel에 일괄 삽입에 대한 다른 질문이 있습니다. 그러나 데이터베이스에 저장하려고 할 때 문제가 발생합니다.문자열 변환에 laravel 대량 삽입 배열
대량 삽입시 insert()
을 사용하고 있습니다. request
을 통해 오는 데이터 배열이 있습니다. 전에 insert
메서드를 사용한 적이 없습니다. 오류를 던지고 있습니다 :
Array to string conversion (SQL: insert into
questions
(answer
,question
,questionnaire_id
) values (1995, What is model of your bike1, ?))
나는 설문지를 만들었습니다. 질문은 jQuery를 사용하여 버튼 클릭에 동적으로 추가됩니다. 여기
나는 데이터를 저장하는 방법을 시도하고있다 :/**
* Create questions
*
*/
public function createQuestions(Request $request)
{
// Insert new records
$data[] = $request->except('_token');
Question::insert($data);
return back()->with('message', 'Questionnaire is being created successfully');
}
편집 : 여기
This is the html code which is being appended by jquery and user can add multiple question
'<div class="question'">
<div class="form-group">'+
<label class="control-label col-md-4" for="question-type">Question Type:</label>
<div class="col-md-4">'+
<select class="form-control question-type" id="'+counter+'">
<option value="text" id='+counter+'>Text</option>
<option value="multiple" id="'+counter+'">Multiple Choice</option>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4" for="question">Enter Question:</label>
<div class="col-md-4">
<input type="text" name="question[]" class="form-control" />'+
</div>
<div class="col-md-4">
<button type="button" class="btn btn-danger btn-delete " id="'+counter+'">Delete Question</button>
</div>
</div>
<div class="form-group txt-answer'+counter+'">
<label class="control-label col-md-4" for="answer">Answer:</label>
<div class="col-md-4">
'<input type="text" name="answer[]" id="answer" class="form-control" />
</div>
</div>
<hr>
<div>
</div>
가
dd
결과
시도해보십시오. 'Question :: create ($ request-> all()); ' –
create는 대량 데이터를 저장하지 않는다고 생각하십니까? –