如何在 laravel 中使用会话变量在编辑页面上显示选中的单选按钮?



我已经在会话中存储了变量的值,并希望显示在编辑页面上。

我的控制器代码是

public function edit($id)
{
$customer_data=DB::table('customers')->select('*')->where('customer_id',$id)->first();
$id= $customer_data->customer_id;
$name= $customer_data->customer_name;
$phone = $customer_data->customer_phone;
$email = $customer_data->customer_email;
$dob = $customer_data->customer_dob;
$city = $customer_data->city;
$gender = $customer_data->customer_gender;
Session::put('id', $id);
Session::put('name', $name);
Session::put('phone', $phone);
Session::put('email', $email);
Session::put('dob', $dob);
Session::put('city', $city);
Session::put('gender', $gender);
return redirect('/admin/customer-record')->with('popup','open');
}

我的边栏选项卡模板代码是

<div class="col-md-8">
<label class="radio-inline radio1"><input type="radio" name="city" value="Prague" @if(Session::get('city') == 'Prague') checked @endif>Prague</label>
<label class="radio-inline radio1"><input type="radio" name="city" value="Other" @if(Session::get('city') == 'Other') checked @endif >Other City</label>
<label class="radio-inline radio1"><input type="radio" name="city" value="Toutist" @if(Session::get('city') == 'Tourist') checked @endif >Tourist</label>
@if ($errors->has('city'))
<span class="help-block">
<strong>{{ $errors->first('city') }}</strong>
</span>
@endif
</div>

尝试以下操作:

<label class="radio-inline radio1"><input type="radio" name="city" value="Prague" {{ Session::get('city') == 'Prague' ? 'checked' : ''}}>Prague</label>

这样做是当会话参数城市等于布拉格时,它将在输入中回显检查。如果不是,它将回显一个空字符串

最新更新