2017-06-11 8 views
2

私はlaravel 5.4.に新しいので、この問題を解決する必要があります。Laravel 5 Viewが正しく機能するようにする必要があります

私は私の会社の出席管理システムに取り組んでいます。フィルタリングされた研修生の目的のために、私はこのような検索コントローラ機能を開発しました。

public function search_code(Request $request){ 
    $query = $request->search; 
    $queryType = $request->institute; // 'id' or 'name' 
    $items = DB::table('registerdetails');   

    if($queryType == 'id'){ 
     $items = $items->where('trainee_id', 'LIKE',"%$query%"); 
    } 
    if($queryType == 'full_name'){ 
     $items = $items->where('full_name', 'LIKE',"%$query%"); 
    } 
    $items = $items->get(); 

    return view('traineeattendance.index')->with('items',$items); 

      } 

だから、その外観を見てください。 enter image description here

ご覧のとおり、これは検索機能のすべての値を返します。これはindex.blade.phpにあります。

次に検索した後、フィルタリングされます。右側の出席ボタンを追加します。出席者フォームの最初のフィールドを追加すると、検索結果に従って自動的に塗りつぶされる必要があります。これはTrainee_Idです。

enter image description here

これはattendance.blade.phpと呼ば出席フォームビューを追加されるようになっています。

<form action="{{route('TraineeAttendance.store')}}" method="post" > 
     {{ csrf_field() }} 
     &nbsp; &nbsp; &nbsp; 

    <div class="form-group"> 

    <label>Trainee ID</label> 
    <input type="text" name="trainee_id" class="form-control" value="MOB/TR/"> 
    </div> 

    <div class="form-group"> 
    <label>Name </label> 
    <input type="text" name="name" class="form-control" value=""> 
    </div> 

    <div class="form-group"> 
      <label >Starting Time</label>  
      <input class="form-control" type="time" value="" id="example-time-input" name="starting_time"> 
    </div> 

    <div class="form-group"> 
      <label >End Time</label>   
      <input class="form-control" type="time" value="" id="example-time-input" name="end_time"> 
    </div> 

    <div class="form-group"> 
      <label >Site Visit Time</label>  
      <input class="form-control" type="time" value="" id="example-time-input" name="site_visit_time"> 
    </div> 

誰でもこの問題を解決するのに役立つことができますか?それは私にとって非常に役に立ちます。 JSで

+0

jQueryのような特定のjsライブラリを使用していますか? – eeya

+0

いいえ、ただラベールとhtmlだけ – Dasun

+0

あなたは検索が必要ですし、すべての検索結果のためにあなたは出席を追加する必要がありますか?私は正しい? –

答えて

0

あなたはonclickイベントリスナーにthisコンテキストを使用して、あなたが必要な各valuesの値が、(例えば練習ID)を取得したことができます。

あなたはこの

<tbody> 
    <tr> 
     <td class="trainee-id"> MOB/TR/Sample 1 </td> 
     <td> Sample Training 1 </td> 
     <td> 2001-12-12 </td> 
     <td> 2001-12-13 </td> 
     <td><a href="#" class="add-attendance" onclick="getTraineeId(this)"> Add Attendance </a></td> 
    </tr> 

    <tr> 
     <td class="trainee-id"> MOB/TR/Sample 2 </td> 
     <td> Sample Training 2 </td> 
     <td> 2001-12-14 </td> 
     <td> 2001-12-15 </td> 
     <td><a href="#" class="add-attendance" onclick="getTraineeId(this)"> Add Attendance </a></td> 
    </tr> 

</tbody> 

のようなあなたのhtml出席リストを設定した後、あなたのJSのために、あなたがこのような値を得ることができますと仮定すると:としてあなたの[フォーム]を次に

<script> 

function getAttendance(oElement) { 
    console.log(oElement) // The DOM Element (e.g add-attendance) 
    var sValue = oElement.parentElement.parentElement.getElementsByClassName('trainee-id')[0].value; // Sample value you will get = MOB/TR/Sample 1 
} 

</script> 

を上記の、あなたの[練習ID]入力フィールドに、[ID]を配置してください:

<label>Trainee ID</label> 
    <input type="text" name="trainee_id" class="form-control" id="input-trainee-id" value="MOB/TR/"> 
</div> 

そこからあなたは以前に取得した値を置いて、あなたはまた、同様に(時間/終了時間を開始例えば名前/)あなたの他の分野に適用することができます

<script> 

function getAttendance(oElement) { 
    console.log(oElement) // The DOM Element (e.g add-attendance) 
    var sValue = oElement.parentElement.parentElement.getElementsByClassName('trainee-id')[0].value; // Sample value you will get = MOB/TR/Sample 1 
} 

document.getElementById('input-trainee-id').value = sValue; 

</script> 

あなたの[練習ID]入力フィールドに割り当てることができます。これがあなたをうまく導くことを願っています。

関連する問題