【发布时间】:2018-12-20 07:01:48
【问题描述】:
如何使用 Laravel 插入多个输入无线电数据?
当我选择一个单选按钮并单击提交表单以插入我的数据库时
这是我的html:
<table class="table table-bordered table-condensed table-hover">
<thead>
<tr>
<th bgcolor="#DFF0D8">
<h5>
<b>
<center>Question No</center>
</b>
</h5>
</th>
<th bgcolor="#DFF0D8">
<h5>
<b>
<center>Yes</center>
</b>
</h5>
</th>
<th bgcolor="#DFF0D8">
<h5>
<b>
<center>No</center>
</b>
</h5>
</th>
</tr>
</thead>
<tbody>
<tr>
<td id="question1">
<h5>1.You Like It's
</h5>
</td>
<!-- true checkbox Q1 -->
<td>
<div class="flat-green single-row">
<div class="radio ">
<center>
<input name="q1[]" type="radio" value="1">
</center>
</div>
</div>
</td>
<td>
<div class="flat-green single-row">
<div class="radio ">
<center>
<input name="q1[]" type="radio" value="0">
</center>
</div>
</div>
</td>
</tr>
<tr>
<td id="question2">
<h5>2.you don't like it's
</h5>
</td>
<!-- true checkbox Q2 -->
<td>
<div class="flat-green single-row">
<div class="radio ">
<center>
<input name="q2[]" type="radio" value="1">
</center>
</div>
</div>
</td>
<td>
<div class="flat-green single-row">
<div class="radio ">
<center>
<input name="q2[]" type="radio" value="0">
</center>
</div>
</div>
</td>
</tr>
</tbody>
</table>
我的 QuestionController.php :
$question = new Question;
$question ->id = $request->get(id);
$question ->question_no = 'question1';
$question ->score = $request->get('q1');
$question ->save();
return redirect('/questionForm/create');
但它只能向数据库插入一行,我想像这样向数据库表插入数据:
|id|user_id|question_no|score|
|1 | 1 | question1 | 1 |
|2 | 1 | question2 | 0 |
如何向数据库表中插入多条数据?
【问题讨论】:
标签: php eloquent laravel-5.6