mercredi 31 mai 2017

Multiple update laravel with checkbox (LARAVEL 5.2)

I want to update the class data on the students I've selected. But I have constraints that the student data I have selected has not been successfully updated correctly. What is the error in writing my code?

The first I have a student table:

{!! Form::open(['method' => 'POST', 'action' => ['SiswaController@pindah_kelas']]) !!}
  <div class="panel panel-primary">
    <div class="panel-heading" align="center">Daftar Data Siswa</div>
    <table id="dataSiswa" class="table table-striped">
      <thead>
        <tr>
          <th><input type="checkbox" name"select-all" id="select-all" />
          <th>NIPD</th>
          <th>NISN</th>
          <th>Nama Siswa</th>
          <th>Kelas</th>
          <th>Action</th>
        </tr>
      </thead>
      <tbody>
        <?php foreach($data_kelas as $siswa): ?>
        <tr>
          <td><input type="checkbox" name="checkbox" id="checkbox" value=""></td>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td>
            <div class="box-button">
              
            </div>
            <div class="box-button">
              
            </div>
            <div class="box-button">
              {!! Form::open(['method' => 'DELETE', 'action' => ['SiswaController@destroy', $siswa->id]]) !!}
                <button type="submit" class="btn btn-danger btn-sm" title="Hapus"><i class="glyphicon glyphicon-trash"></i></button>
              {!! Form::close() !!}
            </div>
          </td>
        </tr>
        <?php endforeach ?>
      </tbody>
    </table>
  </div>
  {!! Form::submit('Pindah Kelas', ['class' => 'btn btn-primary form-control']) !!}
  {!! Form::close() !!}

This is my code javascript:

<script type="text/javascript">
  $(document).ready(function(){
    $('#select-all').click(function(){
      if(this.checked) {
        $(':checkbox').each(function(){
          this.checked = true;
        });
      }
      else {
        $(':checkbox').each(function(){
          this.checked = false;
        });
      }
    });
  });
</script>

And the second this is my Routes:

Route::get('siswa/pencarian_siswa', 'SiswaController@pencarian_siswa');
Route::resource('siswa', 'SiswaController');
Route::post('siswa', 'SiswaController@pindah_kelas');

The last i have controller:

public function pindah_kelas(Siswa $siswa, Request $request)
{
  $input = $request->id;
  $siswa->update($input)->whereIn('id', $input(['id_kelas' => 3]));
  Session::flash('flash_message', 'Data Siswa Berhasil Diupdate.');
  return redirect('kelas');
}

My question is how do I update the transfer of students from the current class into another class from the student data I have selected? I am very grateful if you can help me in solving this problem




Aucun commentaire:

Enregistrer un commentaire