2017-10-06 12 views
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文を使用しますか?しかし、私の選択したフォームでブレードテンプレートを使用してどのように行うことができますか。誰かが私を助けることができますか?

誰かを助けることができたら大変感謝します。 ありがとうございます。ここで

答えて

1

は一例です:

オープン形式:

{{ Form::model($service, array('route' => array('services.update', $service->id))) }} 

選択フォームフィールド:コントローラに

<div class="form-group"> 
    {{ Form::label('Related Agreement') }} 
    {{ Form::select('agreement', $agreementsList, null, array('class'=>'form-control', 'placeholder'=>'Please select ...')) }} 
</div> 

:データを渡すときに

$agreementsList = Agreement::all()->sortBy('name', SORT_NATURAL | SORT_FLAG_CASE)->pluck('name', 'id'); 

は(これを含めますあなたの視点に)

+0

私は試しましたが、ドロップダウンリストからリストを並べ替えて、特定のリソースの現在の値を選択しませんでした –

+0

編集フォームをどのように開いたことがありますか? – kerrin

+0

{!!フォーム::モデル($ channelshows、['route' => ['admin.channelshows.update'、$ channelshows-> id]、 'method' => 'patch'])}このように –

関連する問題