/**
  * Remove the specified resource from storage.
  * @param type int $id
  * @param type Sla_plan $sla
  * @return type Response
  */
 public function destroy($id, Sla_plan $sla)
 {
     $default_sla = Ticket::where('id', '=', '1')->first();
     if ($default_sla->sla == $id) {
         return redirect('departments')->with('fails', 'You cannot delete default department');
     } else {
         $tickets = DB::table('tickets')->where('sla', '=', $id)->update(['sla' => $default_sla->sla]);
         if ($tickets > 0) {
             if ($tickets > 1) {
                 $text_tickets = "Tickets";
             } else {
                 $text_tickets = "Ticket";
             }
             $ticket = '<li>' . $tickets . ' ' . $text_tickets . ' have been moved to default SLA</li>';
         } else {
             $ticket = "";
         }
         $dept = DB::table('department')->where('sla', '=', $id)->update(['sla' => $default_sla->sla]);
         if ($dept > 0) {
             if ($dept > 1) {
                 $text_dept = "Emails";
             } else {
                 $text_dept = "Email";
             }
             $dept = '<li>Associated department have been moved to default SLA</li>';
         } else {
             $dept = "";
         }
         $topic = DB::table('help_topic')->where('sla_plan', '=', $id)->update(['sla_plan' => $default_sla->sla]);
         if ($topic > 0) {
             if ($topic > 1) {
                 $text_topic = "Emails";
             } else {
                 $text_topic = "Email";
             }
             $topic = '<li>Associated Help Topic have been moved to default SLA</li>';
         } else {
             $topic = "";
         }
         $message = $ticket . $dept . $topic;
         /* Delete a perticular field from the database by delete() using Id */
         $slas = $sla->whereId($id)->first();
         /* Check whether function success or not */
         try {
             $slas->delete();
             /* redirect to Index page with Success Message */
             return redirect('sla')->with('success', 'SLA Plan Deleted Successfully' . $message);
         } catch (Exception $e) {
             /* redirect to Index page with Fails Message */
             return redirect('sla')->with('fails', 'SLA Plan can not Delete' . '<li>' . $e->errorInfo[2] . '</li>');
         }
     }
 }
 /**
  * Remove the specified resource from storage.
  * @param type int $id
  * @param type Help_topic $topic
  * @return type Response
  */
 public function destroy($id, Help_topic $topic, Ticket $ticket_setting)
 {
     $ticket_settings = $ticket_setting->where('id', '=', '1')->first();
     if ($ticket_settings->help_topic == $id) {
         return redirect('departments')->with('fails', 'You cannot delete default department');
     } else {
         $tickets = DB::table('tickets')->where('help_topic_id', '=', $id)->update(['help_topic_id' => $ticket_settings->help_topic]);
         if ($tickets > 0) {
             if ($tickets > 1) {
                 $text_tickets = "Tickets";
             } else {
                 $text_tickets = "Ticket";
             }
             $ticket = '<li>' . $tickets . ' ' . $text_tickets . ' have been moved to default Help Topic</li>';
         } else {
             $ticket = "";
         }
         $emails = DB::table('emails')->where('help_topic', '=', $id)->update(['help_topic' => $ticket_settings->help_topic]);
         if ($emails > 0) {
             if ($emails > 1) {
                 $text_emails = "Emails";
             } else {
                 $text_emails = "Email";
             }
             $email = '<li>' . $emails . ' System ' . $text_emails . ' have been moved to default Help Topic</li>';
         } else {
             $email = "";
         }
         $message = $ticket . $email;
         $topics = $topic->whereId($id)->first();
         /* Check whether function success or not */
         try {
             $topics->delete();
             /* redirect to Index page with Success Message */
             return redirect('helptopic')->with('success', 'Helptopic Deleted Successfully' . $message);
         } catch (Exception $e) {
             /* redirect to Index page with Fails Message */
             return redirect('helptopic')->with('fails', 'Helptopic can not Delete' . '<li>' . $e->errorInfo[2] . '</li>');
         }
     }
 }