Support the ongoing development of Laravel.io →
Input Database Forms

Greetings!

I don't know if it's possible or not, but I'd like to retrieve something from a selected option. If a question like this has already been asked, kindly redirect me to it. I'm still a beginner in Laravel so please have patience with me.

Anyways, here's my question:

I have this part of my element to keep the dept_code of the selected item.

<option data-code="{{ $dept->dept_code }}">{{ $dept->dept_name }}</option>

Now i want to get the value of data-code in the element. I'm only able to retrieve the value of $dept->dept_name by using this Input::all() but that's not what I want.

Can anyone help me with this? If I need to provide more info, please tell me. Thanks!

Last updated 3 years ago.
0

IIRC data-* attributes are used mainly for CSS and Javascript. You'll want to use the value attribute

<option value="{{ $dept->dept_code }}">{{ $dept->dept_name }}</option>
0

gizzmo said:

IIRC data-* attributes are used mainly for CSS and Javascript. You'll want to use the value attribute

<option value="{{ $dept->dept_code }}">{{ $dept->dept_name }}</option>

thanks gizzmo, how do we retrieve it then? I think Input::all() will not do the trick.

0
\Input:all();

Will give you all fields, so you would need to do something like

$input = \Input::all();
$var = $input['select'];

This assumes your select is named "select":

<select name="select">
,,,,

You might want to also look at "request" in the docs as well: http://laravel.com/docs/5.1/requests#retrieving-input

0

Sign in to participate in this thread!

Eventy

Your banner here too?

acbadz acbadz Joined 14 Jul 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.