Hye,
I want to get dropdown selected data. For your information, my dropdown data is from my database. I already retrieve data from database and put it inside my dropdown. Right now, I want to make validation. If user key in all information and forgot to key in 1 column data, the dropdown part should get the previous selected data right? So here are my coding, I still can get the previous selected data.
<div> <x-label for="pizzatype" :value="__('Choose pizza type:')" /> <select name="pizzatype" id="pizzatype"> <option selected disabled>Please choose</option> @foreach ($pizzainfo as $pizzaitem) <option value="{{ old('$pizzaitem->name') }}">{{ $pizzaitem->name }}</option> @endforeach </select> </div>
All dropdown button should get the selected previous button…
Advertisement
Answer
As I understand the problem is that you are trying to get an old() value that does not exist… the quick fix is :
<select name="pizzatype" id="pizzatype"> <option @if(!old('pizzatype')) selected @endif disabled>Please choose</option> @foreach ($pizzainfo as $pizzaitem) <option @if(old('pizzatype') == $pizzaitem->name) selected @endif value="{{ $pizzaitem->name }}">{{ $pizzaitem->name }}</option> @endforeach </select>