2016-06-09 2 views
0

"지정"의 값을 업데이트하려고하지만 첫 번째 항목을 클릭하면 양식에 삽입 된 마지막 값이 자동으로 채워집니다. 나는 "FM2"의 값을 업데이트하고 싶다면 예를 들어
나는 형태로 " TST "을 얻을 것이다 :
Laravel을 사용하여 개체 업데이트

Displaying the values

When I click to update "FM2" value

@extends('dashboard.layout') 

@section('title' , 'Manage Sockets') 
@section('pageHeader', 'Sockets') 

@section('content') 

    <div class="card"> 

     <div class="table-responsive"> 
      <table id="data-table-basic" class="table table-striped"> 
       <thead> 
       <tr> 
        <th data-column-id="id" data-type="numeric">ID</th> 
        <th data-column-id="sender">Designation</th> 
        <th data-column-id="received" data-order="desc">Updated on</th> 
        <th data-column-id="operations" data-order="desc">Operations</th> 
       </tr> 
       </thead> 
       <tbody> 
        @foreach($sockets as $socket) 
         <tr> 
          <td>{{$socket->id}}</td> 
          <td>{{$socket->designation}}</td> 
          <td>{{$socket->updated_at}}</td> 
          <td> 
           <a href="{{action('[email protected]', ['id' =>$socket->id ])}}" class="btn bgm-cyan waves-effect"><i class="zmdi zmdi-close"></i></a> 
           <a data-toggle="modal" href="#modalDefault" class="btn bgm-orange waves-effect"><i class="zmdi zmdi-edit"></i></a> 
          </td> 

         </tr> 
        @endforeach 
       </tbody> 
      </table> 

     </div> 

    </div> 
    <div class="modal fade" id="modalDefault" tabindex="-1" role="dialog" aria-hidden="true"> 
     <div class="modal-dialog"> 
      <div class="modal-content"> 
       <div class="modal-header"> 
        <h4 class="modal-title">Update A Socket</h4> 
       </div> 
       <div class="modal-body"> 
        {!! Form::model($socket,['route' =>['socketupdate',$socket->id],'method'=>'POST']) !!} 
        <div class="row"> 
         <div class=" col-sm-offset-1 col-sm-10" > 
          <!-- text input for designation --> 
          <div class="form-group fg-float"> 
           <div class="fg-line"> 
            {!! Form::label('designation', 'designation:',['class' => 'fg-label']) !!} 
            {!! Form::text('designation',null,['class' => 'form-control fg-input input-sm']) !!} 
           </div> 
          </div> 
         </div> 
        </div> 
        <div class="row" > 
         <div class="col-sm-12" > 
          <button class="btn bgm-blue center-block" style="display: flex" type="submit" >Submit</button> 
         </div> 
        </div> 
        {!! Form::close() !!} 
       </div> 
       <div class="modal-footer"> 
        <button data-dismiss="modal" class="btn bgm-cyan btn-icon waves-effect waves-circle waves-float"><i class="zmdi zmdi-close"></i></button> 
       </div> 
      </div> 
     </div> 
    </div> 


    <button class="btn bgm-lightgreen btn-icon waves-effect waves-circle waves-float"> 
     <i class="zmdi zmdi-plus"></i> 
    </button> 
    @include('forms.socket') 

@endsection 

@section('additional_scripts') 
    <script type="text/javascript"> 
     $(document).ready(function(){ 
      $('body').on('click', '#btn-color-targets > .btn', function(){ 
       var color = $(this).data('target-color'); 
       $('#modalColor').attr('data-modal-color', color); 
      }); 
     }); 
    </script> 

@endsection 

가 어떻게이 문제를 해결할 수 있습니다

이 뷰 코드? 코드에서 다음

+0

편집하려는 항목의 ID를 기반으로 한 아약스 요청의 데이터로 모델을 채우고 있습니까? –

+0

아니요 아약스를 사용하지 않는 기본 폼으로 모델을 채우고 있습니다. 폼 빌더의 코드와 거의 같습니다. – hadh

+0

코드를 붙여 넣을 수 있습니까? –

답변

0

중 하나 그렇지 않으면 그것은 단지 것이다 JQuery와 통해 클릭에 동적으로 부트 스트랩 모달의 내용과 경로 매개 변수 ID를 변경처럼 당신이 뭔가를 할 수 또는 하지 않는 것이 좋습니다 각 레코드에 대해 별도의 모든 모델을 설정해야 u가 마지막으로 입력 한 레코드 ID를 가져 와서 설정합니다. 그래서 변화

{!! Form::model($socket,['route' =>['socketupdate',$socket->id],'method'=>'POST']) !!} 

{!! Form::model($socket,['route' =>['socketupdate',rep_id],'method'=>'POST']) !!} 

및 편집 버튼 클릭에 rep_id를 교체하십시오.

+0

좀 더 설명해 주시겠습니까? – hadh

+0

여기에 정적 $ socket-> id를 설정 했으므로 매번 하나의 레코드 만 업데이트하므로 해당 ID를 동적으로 변경해야합니다. –

관련 문제