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

问题描述 投票:2回答:1

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

我的控制器代码是

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>
php laravel laravel-blade
1个回答
0
投票

尝试以下操作:

© www.soinside.com 2019 - 2024. All rights reserved.