/**
  * Listener pos save
  */
 public function postSave()
 {
     if (isset($this->historyLimit) && $this->logHistory()->count() >= $this->historyLimit) {
         $LimitReached = true;
     } else {
         $LimitReached = false;
     }
     if (isset($this->logCleanup)) {
         $LogCleanup = $this->LogCleanup;
     } else {
         $LogCleanup = false;
     }
     if ((!isset($this->auditEnabled) || $this->auditEnabled) && $this->updating && (!$LimitReached || $LogCleanup)) {
         $changes_to_record = $this->changedAuditingFields();
         if (count($changes_to_record)) {
             $fC = [];
             foreach ($changes_to_record as $key => $change) {
                 $fC['old_value'][$key] = array_get($this->originalData, $key);
                 $fC['new_value'][$key] = array_get($this->updatedData, $key);
             }
             $logAuditing = ['old_value' => json_encode($fC['old_value']), 'new_value' => json_encode($fC['new_value']), 'owner_type' => get_class($this), 'owner_id' => $this->getKey(), 'user_id' => $this->getUserId(), 'created_at' => new \DateTime(), 'updated_at' => new \DateTime()];
             $log = new Log();
             \DB::table($log->getTable())->insert($logAuditing);
         }
     }
 }
 /**
  * Audit model
  */
 public function audit(array $log)
 {
     $logAuditing = ['old_value' => json_encode($log['old_value']), 'new_value' => json_encode($log['new_value']), 'owner_type' => get_class($this), 'owner_id' => $this->getKey(), 'user_id' => $this->getUserId(), 'type' => $log['type'], 'created_at' => new \DateTime(), 'updated_at' => new \DateTime()];
     return Log::insert($logAuditing);
 }
 /**
  * Show the logs for the application.
  *
  * @return \Illuminate\Http\Response
  */
 public function show()
 {
     $logs = Log::orderBy('created_at', 'desc')->get();
     return view('log', compact('logs'));
 }