Laravel 获取请求帖子数组

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33760267/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 17:09:16  来源:igfitidea点击:

Laravel get request post array

laravellaravel-5

提问by Ole Haugset

Im using Laravel 5 and Im trying to get a value from my posted form. This works fine for normal form input names, like:

我使用 Laravel 5 并且我试图从我发布的表单中获取一个值。这适用于普通表单输入名称,例如:

$request->input('stripeToken')

However if the input name is a array like name="order['amount']"then I cant get the value. I've tried with:

但是,如果输入名称是一个数组,name="order['amount']"那么我将无法获得该值。我试过:

$request->input( "order['return_url']" )

Anyone got any tips for this?

有人对此有任何提示吗?

回答by Joseph Silber

Use dot notation:

使用点符号:

$value = $request->input('order.return_url');

回答by kscorrales

omit the quotes into the array brackets

省略数组括号中的引号

<input name="order[amount]">
<input name="order[amount2]">

then you can get the value for example

然后你可以得到例如价值

return $request->input('order')['amount'];
return $request->input('order')['amount2'];

or

或者

return $request->get('order')['amount'];
return $request->get('order')['amount2'];