/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id) { $siswa = Siswa::findOrFail($id); $validasi = Validator::make(Input::all(), $siswa->updateRules(), Siswa::$pesan); if ($validasi->fails()) { return Redirect::back()->withInput()->withErrors($validasi); } else { $siswa->nis = Input::get('nis'); $siswa->nisn = Input::get('nisn'); $siswa->nm_siswa = Input::get('nama'); $siswa->jk = Input::get('jk'); $siswa->tmp_lahir = Input::get('tempat'); $siswa->tgl_lahir = date('Y-m-d', strtotime(Input::get('tanggal'))); $siswa->agama = Input::get('agama'); $siswa->nm_ayah = Input::get('ayah'); $siswa->nm_ibu = Input::get('ibu'); $siswa->alamat = Input::get('alamat'); $siswa->thn_sttb = Input::get('tahun'); $siswa->email = Input::get('email'); 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-success'>\n\t\t\t\t\tData berhasil dihapus</div>"); return Redirect::to('admin/siswa/' . $siswa->id); } }