嗨,我在纳税年度中有多个选择下拉列表,选择下拉列表中的数据是
var model = {
comments: {
123: "I disagree on this",
42563: "Sounds correct"
},
answer: {
123: "No",
87: "Yes"
}
};
let wishModel = {}
for(let [k,v] of Object.entries(model)) {
for(let [n, r] of Object.entries(v)) {
wishModel[n] = wishModel[n] || {}
wishModel[n][k] = r
}
}
console.log(wishModel)
select下拉倍数在laravel中传递到控制器时效果很好。现在我的问题是当税收通过时,然后为我的选择下拉倍数添加了一个foreach循环,它工作正常。但是在保存时仅保存了一个数据,因为保存功能在foreach之外。我如何能够传递foreach数据,然后将其保存在foreach循环之外。这是我的下面的代码
2011-2012
2012-2013
2013-2014
2014-2015
2015-2016
2016-2017
2017-2018
答案 0 :(得分:1)
$taxes = $request->get('taxYear');
$mulTax = '';
foreach($taxes as $key=>$tax){
$mulTax = $mulTax . $tax.",";
}
exit;
$case = new Opp([
'code'=>$uNum,
'client_id'=>$cName_0,
'contacts'=>$cName,
'tax_year'=>$mulTax,
'owner'=>$owner,
]);
$case->save();
$retId = $case->id;
Response::json(['success' => true,'id' => $retId], 200);
Session::flash('caseCreated', 'Successfully created cases');
return redirect('cases/create');
答案 1 :(得分:0)
那样使用
使用的计算运算符
$mulTax = "";
foreach($taxes as $key=>$tax){
$mulTax .= $tax.",";
}
$case = new Opp([
'code'=>$uNum,
'client_id'=>$cName_0,
'contacts'=>$cName,
'tax_year'=> rtrim($mulTax,',');, //remove last comma(,) from string
'owner'=>$owner,
]);
答案 2 :(得分:0)
您不需要foreach,请改用implode函数
$taxes = $request->get('taxYear');
$taxes = implode(",", $taxes);
$case = new Opp([
'code'=>$uNum,
'client_id'=>$cName_0,
'contacts'=>$cName,
'tax_year'=>$taxes,
'owner'=>$owner,
]);