0
我有問題在laravel 5.1中插入一個多輸入介紹數據庫。laravel插入多個輸入
我建立了多個輸入的查詢代碼之後,我把他們送到控制器,但我必須有一個問題,將其插入到DB
我怎麼可以插入輸入數據庫,如果結果它是這樣的:
{"_token":"C6m83bcZKaQsOtRiYEKxJAzzZjvdLerl9QpsvSSs","client_id":["aJQsijwqFVG9r0","aJQsijwqFVG9r0"],"short":["4","11"],"url":["567567567567","3453434534"]}
的代碼:
HTML:
<form class="js-validation-material form-horizontal push-10-t" action="{!! url() !!}/addreg" method="post">
{!! csrf_field() !!}
<div class="form-group">
<div id="buildyourform"></div>
</div>
<div class="form-group">
<div class="col-xs-12">
<button class="btn btn-sm btn-primary" type="submit">Submit</button>
</div>
</div>
</form>
<script>
$(document).ready(function() {
$("#add").click(function() {
var intId = $("#buildyourform div.form").length + 1;
var fieldWrapper = $("<div class=\"form col-sm-6 col-lg-6\" id=\"field" + intId + "\"><div class=\"form-material\">");
var client_id = $("<input type=\"hidden\" name=\"client_id[]\" value=\"{!! $task->client_id !!}\" class=\"form-control\" />");
var langname = $("<select type=\"text\" name=\"short[]\" class=\"form-control\">{!! $data['langs'] !!}</select>");
var url = $("<input type=\"text\" name=\"url[]\" class=\"form-control\" placeholder=\"Insert a url..\" />");
var label = ("<label for=\"date\"><h3 class=\"block-title\">Lang" + intId + "</h3></label>");
var removeButton = $("<button class=\"btn btn-danger btn-xs push-5-r push-10\" type=\"button\"><i class=\"fa fa-times\"></i></button>");
removeButton.click(function() {
$(this).parent().remove();
});
$("#buildyourform").append(fieldWrapper);
$("#field" + intId + " .form-material").append(client_id,langname,url,removeButton,label);
});
});
</script>
結果需要在DB中:
DB::table('table')->insert([
['client_id' => $request->client_id],
['short' => $request->short],
['url' => $request->url],
]);
對於每個輸入。
謝謝!非常喜歡 –
不客氣! – Itipacs