【发布时间】:2019-05-16 10:36:15
【问题描述】:
注意:我的问题不重复
我在站点外有表单并使用web api laravel 5.7,现在将这些参数作为帖子发送:
estate: "545345"
id_number: "43534545"
serial_number: "435435345"
type[code_id]: "45345345435"
type[company]: ""
type[country]: ""
type[maintenance_period]: ""
type[model]: "5435345435"
type[name]: "5345345345"
waranty[company_id]: "0"
waranty[duration]: ""
waranty[end]: ""
waranty[start]: ""
表格的一部分:
<input type="text" name="estate" required="">
<input type="text" name="id_number" required="">
<input type="text" name="type[code_id]">
<input type="text" name="type[company]">
现在我想获取type 和waranty 数组:与示例相同:
$type = ['name' => 'test','company' => '...', 'model' => '...' ]
我试试这些代码:
$type = $request->input('type.*'); // NULL
and
$type = $request->input('type'); // NULL
and
$type = Input::get('type'); // NULL
and
$in = $request->all();
$type = $in['type']; // NULL
AND
$request->get('type'); // NULL
AND
$request->post('type') // NULL
不起作用:(,只有我可以通过这种方法获取单个变量:(但我需要数组)
$in = $request->all();
$in['type[code_id]'] ;
我测试type[][code_id],type[][name],... 形式但不起作用:(
我的axios 方法:
serial = function (id) {
var srl = $(id).serializeArray();
var post = {};
for (const k in srl) {
let item = srl[k];
post[item.name] = item.value;
}
return post;
}
axios.post(url, serial("#frm")).then(function (res) {// succs axios ;
console.log(res);
}).catch(err => {// error axios ;
console.log(err);
}); // end axios ;
什么是 Laravel 原生解决方案?对于这个问题?
注意:我可以创建一个函数来解决这个问题,但我需要 laravel 原生解决方案。
【问题讨论】:
-
你试过
$request->get('type'); -
那么我认为您必须将类型参数作为数组值发送。然后在 Laravel 中你可以将它用作数组
-
@RohitRasela 是的诅咒 :(
-
您尝试
$request->get('type');输入名称type[][code_id]? -
@RohitRasela 是的,兄弟,我测试了它,但除了
NULL
标签: php arrays laravel laravel-5.7