【发布时间】:2019-02-10 09:57:39
【问题描述】:
我正在尝试使用多语言发布表单。例如,我有 en、es、ru 语言。我需要将 en 保存到一张桌子上。 Es 和 ru 形式必须保存到翻译表中。但我无法将所有数据传递给 controller@store 函数。如何将所有数据分别传递给控制器?
我正在通过紧凑的语言传递。像这样:
public function index()
{
$langs = [];
foreach(LaravelLocalization::getSupportedLocales() as $localeCode => $properties)
{
$langs[]= $localeCode;
}
return view('backEnd.langview', compact('langs'));
}
在视图中,我有每种语言的选项卡面板。这是视图:
@foreach(LaravelLocalization::getSupportedLocales() as $localeCode => $properties)
@if($loop->first)
<div class="tab-pane animated fadeIn text-muted active" id="tab{{$localeCode}}" aria-expanded="false">{{$localeCode}}
<form method="POST" id="form{{$localeCode}}" action="{{route('send_slug')}}">
{{csrf_field()}}
<input type="text" name="main_title" placeholder="title here">
<input type="text" name="main_slug" placeholder="slug here">
</form>
</div>
@else
<div class="tab-pane animated fadeIn text-muted" id="tab{{$localeCode}}" aria-expanded="false">{{$localeCode}}
<form method="POST" id="form{{$localeCode}}" action="{{route('send_slug')}}">
{{csrf_field()}}
<input type="text" name="title[]" placeholder="title here other languages">
<input type="text" name="slug[]" placeholder="slug here other languages">
</form>
</div>
@endif
@endforeach
我用 ajax 试过了:
<script>
var langcodes = @json($langs);
var i = 0;
submitForms = function(){
langcodes.forEach(function (data) {
i++;
var formdata = $('#form'+data).serialize();
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
}
});
jQuery.ajax({
url: '{{route('send_slug')}}',
method: 'post',
data: {
formdata
}
});
});
}
但每次尝试,我只能通过第一语言或最后一种语言。我需要分别发送所有语言。 我希望我能表达自己。对不起我的语言。提前致谢。
【问题讨论】:
-
如果对我的回答有帮助,请接受我的回答
标签: javascript php ajax laravel forms