Skip to content
Advertisement

Getting Values from Laravel drop-down form

I have a simple drop-down in a form.

The form is:

JavaScript

In the view function in the controller the array is:

JavaScript

The store function in the controller is:

JavaScript

The method, however, stores the position of the values instead of the value itself. So, if I do a dd(request()->all());, I get:

JavaScript

How can I get the values instead of the position?

Advertisement

Answer

Since you are receiving the array key to a specific array element, you just need to make sure you can access that array to retrieve the value when needed.

JavaScript

OR

You can change your array to define keys as you want them so that when you use Form::select it uses the keys you specified as the html element value.

Your array have to look like this then:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement