当我更新表单时,如何保留选择选项中的旧值?表格:
<select class="form-select" name="slug" id="slug" value="{{$project->slug ?? '' }}"> <option value="">Select Category </option> <option value="commercial">commercial</option> </select>
jslywgbw1#
可以像这样使用old()
old()
<select class="form-select" name="slug" id="slug"> <option value="commercial" {{ old('slug', $project->slug) == 'commercial' ? 'selected' : '' }}>Commercial</option> <option value="another" {{ old('slug', $project->slug) == 'another' ? 'selected' : '' }}>Another</option> <option value="anotherrr" {{ old('slug', $project->slug) == 'anotherrr' ? 'selected' : '' }}>Anotherrr</option> </select>
oalqel3c2#
只需使用@selected(bool),如果条件为真,它将返回selected。
@selected(bool)
<select class="form-select" name="slug" id="slug"> <option value="commercial" @selected(old('slug', $project->slug) == 'commercial')>Commercial</option> <option value="another" @selected(old('slug', $project->slug) == 'another')>Another</option> </select>
2条答案
按热度按时间jslywgbw1#
可以像这样使用
old()
oalqel3c2#
只需使用
@selected(bool)
,如果条件为真,它将返回selected。