php - 如何使用 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>
这样做是当会话参数城市等于布拉格时,它将在输入中回显检查。如果不是,它将回显一个空字符串
推荐阅读
- android - Espresso 不会等到 RecyclerView 从 LiveData 获取更新
- python-3.x - discord.ext.commands.errors.CommandInvokeError:命令引发异常:IntegrityError:唯一约束失败:main.Players
- python - 在 Python 中编写 Discord 机器人 - 如何在嵌入中缩进?
- c# - 检查电子邮件是否已存在于 Firebase Auth unity中
- html - 当两者都在可滚动容器内时,防止子溢出父
- reactjs - 如何模拟默认的 createHook 和命名的 createHook 导出?
- html - HTTP 1.1 GET 请求太快,服务器无法响应,导致 TCP 重传
- python - 不断收到以下语法错误:async def on_ready():
- python - Streamlit 自动填充多选小部件以过滤数据框
- vba - Access DoCMD.OpenReport acViewPreview 从不打开预览并冻结 Access