猿问

如何在Laravel中的编辑视图中获取记录drom数据库?

在我的编辑视图中,我有这样的代码


<div class="form-group">

    <label class="col-md-12">Last Name</label>

    <div class="col-md-12">

        <input type="text" placeholder="Enter Last Name" name="lastName" class="form-control form-control-line" value="{{$profile->personal_detail['last_name']}}" required>

    </div>

</div>


<div class="form-group">

    <label class="col-md-12">Department</label>

    <div class="col-md-12">

        <select class="custom-select form-control col-md-11" id="department" name="department">{{ $profile->personal_profile['department'] }}

            @foreach($listDepartment as $departmentList){

                <option value='{{$departmentList->nameOfDepartment}}'>{{$departmentList->nameOfDepartment}}</option>

            }

            @endforeach

        </select>

    </div>

</div>

在“编辑”视图的“我的姓氏”字段中,它为我提供了数据库的姓氏,在“部门”中,它显示我部门的下拉列表,但我希望在该字段中插入部门的名称。


我怎么才能得到它??


我还有其他这样的下拉菜单


<div class="row">

<label class="col-md-6"><b> Mode </b></label>

<div class="col-md-6">

<select class="custom-select form-control col-md-12" name="mode" id="mode" required>

   <option value=""> --- Select Interciew Mode --- </option>

   <option value="telephonic">Telephonic</option>

   <option value="facetoface">Face 2 face</option>

   <option value="skype">Skype</option>

</select>

</div>

</div><hr>

这是我的控制器


public function candidateDetail($id)

    {

        $empDetails = User::all();

        $candidateDetail = EmployeeHire::find($id);


        $interview = [

            '' => '--- Select Interciew Mode ---',

            'telephonic' => 'Telephonic',

            'facetoface' => 'Face 2 face',

            'skype' => 'Skype'

        ];


        return view('pages.candidatedetails', compact('id', 'candidateDetail', 'empDetails', 'interview'));

    }


海绵宝宝撒
浏览 141回答 1
1回答

达令说

您可以从您的用户中检查匹配的foreach值nameOfDepartment。<div class="form-group">&nbsp; &nbsp; <label class="col-md-12">Department</label>&nbsp; &nbsp; <div class="col-md-12">&nbsp; &nbsp; &nbsp; &nbsp; <select class="custom-select form-control col-md-11" id="department" name="department">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @foreach($listDepartment as $departmentList)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @if ($profile->personal_profile['department'] == $departmentList->nameOfDepartment)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option value="{{$departmentList->nameOfDepartment}}" selected="selected">{{$departmentList->nameOfDepartment}}</option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @else&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option value="{{$departmentList->nameOfDepartment}}">{{$departmentList->nameOfDepartment}}</option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @endif&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @endforeach&nbsp; &nbsp; &nbsp; &nbsp; </select>&nbsp; &nbsp; </div></div>对于第二个选择字段,请在控制器中创建一个包含所有可能值的数组。$interview = [&nbsp; &nbsp; '' => '--- Select Interciew Mode ---',&nbsp; &nbsp; 'telephonic' => 'Telephonic',&nbsp; &nbsp; 'facetoface' => 'Face 2 face',&nbsp; &nbsp; 'skype' => 'Skype'];然后,您可以执行与先前选择相同的操作:<select class="custom-select form-control col-md-12" name="mode" id="mode" required>&nbsp; &nbsp; @foreach($interview as $key => $name)&nbsp; &nbsp; &nbsp; &nbsp; @if ($profile->personal_profile['interview'] == $key)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option value="{{ $key }}" selected="selected">{{ $name }}</option>&nbsp; &nbsp; &nbsp; &nbsp; @else&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option value="{{ $key }}">{{ $name }}</option>&nbsp; &nbsp; &nbsp; &nbsp; @endif&nbsp; &nbsp;@endforeach</select>
随时随地看视频慕课网APP
我要回答