I am trying to use 'old' in a Laravel 5 app to pre-populate a select form on an edit route like this...
<select id="category" name="category" required>
<option value="">Select</option>
<option value="animal" @if (old('category') == "animal") selected @endif>Animal</option>
<option value="vegetable" @if (old('category') == "vegetable") selected @endif>Vegetable</option>
<option value="mineral" @if (old('category') == "mineral") selected @endif>Mineral</option>
</select>
This works well and keeps the selected option if a validation fails, but I am trying to make it work so that it pre-populates when the page first loads.
How do I determine if this is the first load of the edit page, or if it has reloaded after a validation failure? Or is there a better way to do this?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire