php Laravel 5 获取数组的输入值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30831900/
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
Laravel 5 getting input values that are arrays
提问by Tartar
I have a text field like
我有一个像
{!! Form::textarea('representive[address_1]' ,null ,['class' =>'textboxlong form-control','style'=>'height:60px;']) !!}
In my form. And when I try to get its value in my controller but it comes null. What I try is
以我的形式。当我尝试在我的控制器中获取它的值时,它却为空。我尝试的是
$adress = Request::get('representive.0.address_1');
I also tried some other ways but could not end up with a proper solution. How can I get the value of this field? Any help would be appreciated.
我也尝试了其他一些方法,但最终无法找到合适的解决方案。我怎样才能得到这个字段的值?任何帮助,将不胜感激。
回答by Bogdan
The Request::get()
method is implemented by Symfony\Component\HttpFoundation\Request
which the Illuminate\Http\Request
class extends. This method does not parse the string parameter passed using the dot notation as Laravel does. You should instead be using the Request::input
which does:
该Request::get()
方法由实施Symfony\Component\HttpFoundation\Request
该Illuminate\Http\Request
类延伸。此方法不像 Laravel 那样解析使用点表示法传递的字符串参数。您应该改为使用Request::input
which :
$adress = Request::input('representive.address_1');
As an alternative you can also use the Input
facade and do Input::get()
.
作为替代方案,您还可以使用Input
facade 和 do Input::get()
。