Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

saurabh799@gmail.com's avatar

How to get value from Select box

I am using $request->usertype or $request->input('usertype') in my controller to try to get selected value in view They give me $type->id rather than the selected value from my view $type->type...how can I get that ....

''' @if(!empty($types))
@foreach($types as $type) id}}">{{$type->type}} @endforeach
@endif '''

Please do not suggest me $valTypes = Input::get('usertype'); it gives Input not found even after I added use App\Http\Controllers\Input in my controller

0 likes
6 replies
joedawson's avatar

What does your select actually look like? Something like this usually works for me just fine.

<select name="type">
    @foreach($types as $type)
        <option value="{!! $type->id !!}">{!! $type->type !!}</option>
    @endforeach
</select>

Then in your controller fetch the value from the selects name attribute as you usually would.

$request->get('type');
2 likes
saurabh799@gmail.com's avatar

This still gives me value of $type ->id rather than $type->type. You can try on your own and see .... Let me know if you have any solution to get the selected value from the select box.

1 like
IsaacBen's avatar

@saurabh799@gmail.com I'm dealing a lot with select forms now. What you put in the value is what will be selected.

Here is an example that works for me:

        <div class="form-group">
            <label for="jobPriority">Job Priority:</label><br>
            <select class="textWidth form-control" name="jobPriority" id="jobPriority" type="text">
                <option disabled selected> -- select an option -- </option>
                @foreach($priority as $priorities)
                  <option value="{{$priorities->id}}">
                    {{$priorities->name}}
                  </option>
                @endforeach
            </select>
        </div>

Than I just do:

$priorityID = $request->get('jobPriority');

There is no magic here, this must work for you. I tested it myself right now

2 likes
joedawson's avatar

Then just change the option's value to the type...

<option value="{!! $type->type !!}">{!! $type->type !!}</option>
1 like
Jaytee's avatar

You can also just grab the data by giving the Select box a name

<select class="form-control" name="answer">
    // Options go here
</select>

<?php

$answer = $request->answer OR $request->input('answer');

?>
Tatata's avatar

@JOEDAWSON - Did you add anything into your route? Or you directly get the value by just using $request->get('type');?

Please or to participate in this conversation.