Example #1
0
 public function delete(Request $request)
 {
     if ($request->ajax()) {
         if (\Auth::user()->id == $request->input('id')) {
             return response('Anda tidak bisa menghapus akun Anda sendiri.', 422);
         }
         $guru = null;
         try {
             $guru = Guru::findOrFail($request->input('id'));
         } catch (Exception $e) {
             return response('Gagal; guru dengan ID tersebut tidak ditemukan.', 422);
         }
         if (Guru::self_destruct_check($request->input('id'))) {
             return response('Harus ada minimal satu akun guru yang berupa staf.', 422);
         }
         if ($guru->delete()) {
             return response('Akun telah dihapus.', 200);
         } else {
             return response('Akun gagal dihapus.', 422);
         }
     } else {
         abort(404);
     }
 }