我已经在网上研究了很多例子以保留所选择的选项。但是,它对我没有用。我的例子如下所示: -
form in blade.html
<form method="get" action="">
<select name="developer" id="developer" required="">
@foreach($developer_option as $key => $data)
<option value="{{$data->id}}" @if (old('developer') == $data->id) selected @endif>{{$data->developer_name}}</option>
@endforeach
</select>
<input type="submit" name="submit" value="check" class="btn btn-sm mt-4">
</form>
从上面的表单中,我想在选项标记中使用@if (old('developer') == $data->id) selected @endif
保留所选选项。
这是我的控制器
use App\Model\Developer;
class DeveloperController extends Controller
{
public function index(Request $request)
{
$selected_developer_id = $request->input('developer');
$from = $request->input('from_developer');
$to = $request->input('to_developer');
$developer_option = Developer::orderBy('developer_name','asc')->select('developer_name','id')->get();
return view('SAM.Developer.developer',compact('developer_filtered','developer_option'));
}
}
但是,在我点击提交表单后,选择器没有显示我选择的选项。