Reputation: 2007
I'am trying to show a certian Country from a dropdown list when a user clicks on a certian ID to edit a form.
This is how my edit.blade.php form field looks like:
<div class="form-group">
<label for="country">Country:</label>
<select id="country" name="country" class="form-control">
@foreach(App\Http\Utilities\Country::all() as $country)
<option value="{{ Request::old('country') ? : $flyers->country }} ">{{ Request::old('country') ? : $flyers->country }}</option>
@endforeach
</select>
</div>
It works, BUT, when u click on the drop down it just repeats That one country that is selected over and over again until it reaches the bottom of the list.
@foreach(App\Http\Utilitites\Country::all() as $country is coming from my countries array I made in my folder. It takes the array and lists all the countries.
Is there a way that it can show my edited form field country, and show the other countries as well without repeating that one selected country over and over again?
Upvotes: 0
Views: 2851
Reputation: 12295
You can do something like this:
<div class="form-group">
<label for="country">Country:</label>
<select id="country" name="country" class="form-control">
@foreach(App\Http\Utilities\Country::all() as $country)
<option value="{{ $country }}" {{ $flyers->country == $country ? "selected" : "" }}>{{ $country }}</option>
@endforeach
</select>
</div>
On this way if one of your values equals the requested value, it gets selected
Upvotes: 1