Javascript 使用single submit(Laravel)将表中的数据保存到数据库中
我有一个视图,用户填写表单并将其提交到数据库中。表单中有一个表,表中的行是动态创建的。 用户可以添加新行并填充它们 view.blade.phpJavascript 使用single submit(Laravel)将表中的数据保存到数据库中,javascript,mysql,forms,laravel-5,eloquent,Javascript,Mysql,Forms,Laravel 5,Eloquent,我有一个视图,用户填写表单并将其提交到数据库中。表单中有一个表,表中的行是动态创建的。 用户可以添加新行并填充它们 view.blade.php <fieldset> <div class="row"> <div class="col-xs-12"> <div id="LMOtablediv"> <input type="button" id="addmoreLMObutton" value
<fieldset>
<div class="row">
<div class="col-xs-12">
<div id="LMOtablediv">
<input type="button" id="addmoreLMObutton" value="Add" onclick="insRow(event)" />
<table id="addLMOtable" border="1">
<thead>
<tr>
<td>No.</td>
<td>Name</td>
<td>Risk Level</td>
<td>Quantity</td>
<td>Volume</td>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>{!! Form::text('lmoname', null, array('id'=>'lmoname'))!!}</td>
<td>{!! Form::text('lmorisk_level', null, array('id'=>'lmorisk_level'))!!}</td>
<td>{!! Form::number('lmoquantity', null, array('id'=>'lmoquantity'))!!}</td>
<td>{!! Form::number('lmovolume', null, array('id'=>'lmovolume'))!!}</td>
<td>{{ Form::hidden('lmonotification_type', '1', null, array('id'=>'lmonotification_type')) }}</td>
<td><input type="button" id="delPOIbutton" value="Delete" onclick="deleteRow(this)"/></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</fieldset>
控制器文件
public function create(Request $request)
{
$notification = new AddNotification;
$notification->lmoname = $request->lmoname;
$notification->lmorisk_level = $request->lmorisk_level;
$notification->lmoquantity = $request->lmoquantity;
$notification->lmovolume = $request->lmovolume;
$notification->user_id = Auth::user()->id;
$notification->save();
return redirect('home/notification/notificationForm');
// return view('ApplicationForms.notifi', $notification);
}
问题是,当我添加新行、填充它们并提交时,只有最后一行更新到数据库中。如果我想一次提交多行,我知道这不是编写控制器代码的正确方法。
任何人都可以指导如何做吗?您需要使用HTML中的数组命名,例如:
,以便为变量$request->lmoname
获取一个数组,不确定如何使用表单facade,但可能会有所帮助我正在寻找需要在控制器中进行的更改。你能帮个忙吗?是的,你能发布dd($request->lmoname)
的输出来检查值是否作为数组返回吗
public function create(Request $request)
{
$notification = new AddNotification;
$notification->lmoname = $request->lmoname;
$notification->lmorisk_level = $request->lmorisk_level;
$notification->lmoquantity = $request->lmoquantity;
$notification->lmovolume = $request->lmovolume;
$notification->user_id = Auth::user()->id;
$notification->save();
return redirect('home/notification/notificationForm');
// return view('ApplicationForms.notifi', $notification);
}