1
我想在編輯表格中的特定資源時回顯所選值。當我編輯特定資源時,應在我的下拉列表中顯示當前數據,但在實際情況下,它會顯示列表中的第一個錯誤。那麼如何在laravel中使用刀片在下拉選項中回顯所選值?Laravel如何在更新特定資源時使用刀片在回撥中回顯選定的值
這裏低於
<!-- Shows Field -->
<div class="form-group col-sm-6">
{!! Form::label('show_id', 'Shows:') !!}
{!! Form::select('show_id', $shows, $shows, ['class' => 'form-control input-md','required'])!!}
</div>
{{-- {{ $channelshows->channel->name }} --}}
<!-- Client Id Field -->
<div class="form-group col-sm-6">
{!! Form::label('channel_id', 'Channels:') !!}
{!! Form::select('channel_id', $channel, $channel, ['class' => 'form-control input-md','required'])!!}
</div>
<!-- Submit Field -->
<div class="form-group col-sm-12">
{!! Form::submit('Save', ['class' => 'btn btn-primary']) !!}
<a href="{!! route('admin.channelshows.index') !!}" class="btn btn-default">Cancel</a>
</div>
的我在視圖代碼一些示例,這裏是在低於我控制器的代碼。
public function edit($id)
{
$channelshows = $this->channelshowsRepository->findWithoutFail($id);
$shows = Show::pluck('name', 'id');
$channel = Channel::pluck('name', 'id');
if (empty($channelshows)) {
Flash::error('Assigned show not found');
return redirect(route('admin.channelshows.index'));
}
return view('admin-dashboard.channelshows.edit', compact('shows', $shows), compact('channel', $channel))->with('channelshows', $channelshows);
}
即使我更新了特定的資源,這裏的一切工作正常。我只想自動填充或選擇我將更新的資源的當前值,因爲當我編輯特定資源時,它會顯示列表中的第一個資源。
我打算在刀片中使用@if語句嗎?但是,如何使用我選擇的表單中的刀片模板來完成此操作。有人能幫助我嗎?
感謝有人能幫忙。 在此先感謝。
我試過了,但它只是從下拉列表中排序列表,它沒有選擇特定資源的當前值 –
您是如何打開編輯表單的? – kerrin
{!! Form :: model($ channelshows,['route'=> ['admin.channelshows.update',$ channelshows-> id],'method'=>'patch'])!!}這樣的 –