我正在尝试在db上插入多行,这些行将通过excel表粘贴,已经由逗号连接
示例:
如何插入多行?
查看:
<form action="insert" method="post">
@csrf
<label for="values" class="control-label">Values:</label>
<div class="form-group">
<textarea name="data" id="data" rows="10" cols ="50">
name,fullname,age
name2,fullname,age
name3,fullname,age
name4,fullname,age
</textarea>
</div>
</form>
控制器:
public function insert(Request $request)
{
$data= explode("\n",$request->data);
$array = array_filter($data, 'trim')
foreach($arry as $line){
Tabletarget::insert($data);
}
}
答案 0 :(得分:0)
尝试一下...
<form action="/insert" method="post">
@csrf
<label for="values" class="control-label">Values:</label>
<div class="form-group">
<input type="text" name="data[]" value="name" />
<input type="text" name="data[]" value="fullname" />
<input type="text" name="data[]" value="age" />
<button id="btn-save" name="btn-save" type="submit" name="submit"
class="btn btn-warning btn-lg btn-save">
</div>
</form>
public function insert(Request $request)
{
$data= explode("\n",$request->data);
$array = array_filter($data, 'trim')
$datas = Input::get('data');
foreach($datas as $data) {
Tabletarget::insert($data);
}
}
查看更多详细信息。.Laravel Forms
享受编码〜! :)