public function get_guru() { if (Request::ajax()) { $nip = Input::get('nip'); $guru = Guru::find($nip); return $guru->nm_guru; } }
public function update_profile() { $guru = Guru::find(Sentry::getUser()->username); $guru->nuptk = Input::get('nuptk'); $guru->nm_guru = Input::get('nama'); $guru->tmp_lahir = Input::get('tempat'); $guru->tgl_lahir = Input::get('tanggal'); $guru->pend_terakhir = Input::get('pend'); if (Input::hasFile('foto')) { $file = Input::file('foto'); $filename = str_random(5) . '-' . $file->getClientOriginalName(); $destinationPath = 'uploads/guru/'; $file->move($destinationPath, $filename); if ($guru->foto) { $fotolama = $guru->foto; $filepath = public_path() . DIRECTORY_SEPARATOR . 'uploads/guru' . DIRECTORY_SEPARATOR . $guru->foto; try { File::delete($filepath); } catch (FileNotFoundException $e) { } } $guru->foto = $filename; } $guru->save(); Session::flash('pesan', "<div class='alert alert-success'>\n Data Berhasil diupdate</div>"); return Redirect::back(); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $rombel = DB::table('rombel')->where('id_wali', '=', $id)->count(); $mengajar = DB::table('mengajar')->where('id_guru', '=', $id)->count(); if ($rombel > 0 && $mengajar > 0) { $html = "<hr><div class='alert alert-danger'>Data Guru masih ada relasi \n\t\t\tdengan Data Rombel dan Data Mengajar</div>"; } else { if ($rombel > 0) { $html = "<hr><div class='alert alert-danger'>Data Guru tidak dapat dihapus\n\t\t\tkarena Masih ada relasi dengan\n\t\t\tdata Rombel <ul>"; $data = DB::table('rombel')->where('id_wali', '=', $id)->get(); foreach ($data as $row) { $html .= "<li>" . $row->kd_rombel . "</li>"; } $html .= "</ul></div>"; Session::flash('pesan', $html); return Redirect::back(); } else { if ($mengajar > 0) { $html = "<hr><div class='alert alert-danger'>Data Guru tidak dapat dihapus\n\t\t\tkarena Masih ada relasi dengan\n\t\t\tdata Mengajar <ul>"; $data = DB::table('mengajar')->where('id_guru', '=', $id)->get(); foreach ($data as $row) { $html .= "<li>" . $row->id_mengajar . "</li>"; } $html .= "</ul></div>"; Session::flash('pesan', $html); return Redirect::back(); } else { $guru = Guru::find($id); if ($guru->foto) { $fotolama = $guru->foto; $filepath = public_path() . DIRECTORY_SEPARATOR . 'uploads/guru' . DIRECTORY_SEPARATOR . $guru->foto; try { File::delete($filepath); } catch (FileNotFoundException $e) { } } $guru->delete(); return Redirect::to('admin/guru')->with('pesan', "<hr><div class='alert alert-info'>Data Berhasil dihapus</div>"); } } } }