public static function rubah($id, $foto, $nis, $nama, $kelas, $telp, $alamat) { $siswa = Siswa::find($id); if ($foto != null) { $siswa->foto = $foto; } $siswa->nis = $nis; $siswa->nama = $nama; $siswa->kelas = $kelas; $siswa->telp = $telp; $siswa->alamat = $alamat; $siswa->save(); }
public function update_profile() { $siswa = Siswa::find(Input::get('nis')); $siswa->nm_siswa = Input::get('nama'); $siswa->tmp_lahir = Input::get('tempat'); $siswa->tgl_lahir = date('Y-m-d', strtotime(Input::get('tanggal'))); $siswa->nm_ayah = Input::get('ayah'); $siswa->nm_ibu = Input::get('ibu'); $siswa->alamat = Input::get('alamat'); $siswa->thn_sttb = Input::get('tahun'); if (Input::hasFile('foto')) { $file = Input::file('foto'); $filename = str_random(5) . '-' . $file->getClientOriginalName(); $destinationPath = 'uploads/siswa/'; $file->move($destinationPath, $filename); //$siswa->foto=$filename; if ($siswa->foto) { $fotolama = $siswa->foto; $filepath = public_path() . DIRECTORY_SEPARATOR . 'uploads/siswa' . DIRECTORY_SEPARATOR . $siswa->foto; try { File::delete($filepath); } catch (FileNotFoundException $e) { } } $siswa->foto = $filename; } $siswa->save(); Session::flash('pesan', "<div class='alert alert-info'>\n Data Berhasil diupdate</div>"); return Redirect::back(); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $siswa = Siswa::find($id); $cek = DB::table('siswa_rombel')->where('nis', '=', $siswa->nis)->count(); $harian = DB::table('nilai_harian')->where('nis', '=', $siswa->nis)->count(); $ujian = DB::table('nilai_ujian')->where('nis', '=', $siswa->nis)->count(); if ($cek > 0 && $harian > 0 && $ujian > 0) { $html = "<div class='alert alert-danger'>Data tidak dapat dihapus\n\t\t\tkarena ada relasi dengan tabel lain</div>"; Session::flash('pesan', $html); return Redirect::back(); } else { if ($cek > 0) { $html = "<hr><div class='alert alert-danger'>Data Gagal dihapus\n\t\t\tkarena masih memiliki relasi dengan data rombel<ul>"; $rombel = DB::table('siswa_rombel')->where('nis', '=', $id)->get(); foreach ($rombel as $row) { $html .= "<li>" . $row->kd_rombel . "</li>"; } $html .= "</ul></div>"; Session::flash('pesan', $html); return Redirect::back(); } else { if ($harian > 0) { $html = "<hr><div class='alert alert-danger'>Data Gagal dihapus\n\t\t\tkarena masih memiliki relasi dengan data nilai harian</div>"; Session::flash('pesan', $html); return Redirect::back(); } else { if ($ujian > 0) { $html = "<hr><div class='alert alert-danger'>Data Gagal dihapus\n\t\t\tkarena masih memiliki relasi dengan data nilai ujian</div>"; Session::flash('pesan', $html); return Redirect::back(); } else { $siswa = Siswa::find($id); if ($siswa->foto) { $fotolama = $siswa->foto; $filepath = public_path() . DIRECTORY_SEPARATOR . 'uploads/siswa' . DIRECTORY_SEPARATOR . $siswa->foto; try { File::delete($filepath); } catch (FileNotFoundException $e) { } } $siswa->delete(); Session::flash('pesan', "<hr><div class='alert alert-info'>Data Siswa\n\t\t\t\tBerhasil dihapus</div>"); return Redirect::back(); } } } } }
public function get_siswa() { if (Request::ajax()) { $nis = Input::get('nis'); $siswa = Siswa::find($nis); echo $siswa->nm_siswa . "|" . $siswa->jk; } }