5

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.

Casper Spruit
  • 944
  • 1
  • 13
  • 31
Tartar
  • 5,149
  • 16
  • 63
  • 104
  • Shouldn't that be `Request::get('representative');` and then take the values from that array? – Joel Hinz Jun 14 '15 at 16:47
  • Just do `Request::get('representative.address_1');`. The ".0" part is what shouldn't be there. Also you misspelled the variable as "$adress" by the way. – orrd Jun 14 '15 at 17:12
  • @orrd `Request::get('representative.address_1');` does not work. I tried it already – Tartar Jun 14 '15 at 17:47
  • Oh, sorry I actually what I should have said was `Input::get('representative.address_1');`. The `Request::get()` method doesn't understand dot notation because it's a Symfony method. Otherwise, Joel Hinz's answer would also work if you need to use Request::get() for some reason. – orrd Jun 14 '15 at 18:28

1 Answers1

6

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:

$adress = Request::input('representive.address_1');

As an alternative you can also use the Input facade and do Input::get().

Bogdan
  • 43,166
  • 12
  • 128
  • 129
  • I just tested `Request::input('representive.address_1');` and it works just fine. Try doing a `dd(Input::all());` in your controller and see if you are actually getting the parameter value from the client. – Bogdan Jun 14 '15 at 18:39
  • The value of that `{!! Form::textarea('representive[address_1]' ,null ,['class' =>'textboxlong form-control','style'=>'height:60px;']) !!}` field does not appear in `dd(Input::all());` array when i return it, not sure why. – Tartar Jun 14 '15 at 18:42
  • Then it most likely has something to do with the form itself. Please post more code from your form. How are you submitting the form: synchronously or with an AJAX request? – Bogdan Jun 14 '15 at 18:46
  • Ajax would be more complex as i am a L5 newbie. Rest of the form seems fine, which part of the form might be causing this problem do you think ? – Tartar Jun 14 '15 at 18:49
  • I can't really say without seeing the entire form code. – Bogdan Jun 14 '15 at 18:50
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/80528/discussion-between-tartar-and-bogdan). – Tartar Jun 14 '15 at 18:52