Ad

Request Values Of Contoller Not Getting Value Of Select

- 1 answer

This is a noob question, I send a post request to my controller and all it can get is the request of the input. What I want is I can also get the value of $cat array.

Here's my blade:

            @if (!$categories->isEmpty())
                <form action="{{route('subcategory.store')}}" method="POST">
                    @csrf
                    <div class="row">
                        <div class="input-group mb-3 col-md-4">
                            <div class="input-group-prepend">
                                <label class="input-group-text" for="inputGroupSelect01">Choose Category:</label>
                            </div>
                            <select class="custom-select" id="inputGroupSelect01">
                                @foreach ($categories as $cat)
                                <option value="{{$cat->id}}">{{$cat->name}}</option>
                                @endforeach
                            </select>
                        </div>
                        <input type="text" name="subcat" id="subcat" class="form-control col-md-3 ml-5">
                        <button type="submit" class="btn btn-success btn-lg ml-3">Save Sub Category</button>
                    </div>
                </form>
            @endif

And here's my returned value.

{"_token":"XlzwIt2jFqcybqqSjwLLJIAChG5tui7gvHzlaeAq","subcat":"xx"}

Ad

Answer

You forgot to add name="cat" in select i guess

<select class="custom-select" id="inputGroupSelect01">

simple add name="" attr

<select class="custom-select" id="inputGroupSelect01" name="cat">
Ad
source: stackoverflow.com
Ad