/** * Called after record successfully created */ public function postCreate() { // Check if we should store creations in our revision history // Set this value to true in your model if you want to if (empty($this->revisionCreationsEnabled)) { // We should not store creations. return false; } if (!isset($this->revisionEnabled) || $this->revisionEnabled) { $revisions[] = array('revisionable_type' => get_class($this), 'revisionable_id' => $this->getKey(), 'key' => 'created_at', 'old_value' => null, 'new_value' => $this->created_at, 'user_id' => $this->getUserId(), 'created_at' => new \DateTime(), 'updated_at' => new \DateTime()); $revision = new Revision(); \DB::table($revision->getTable())->insert($revisions); } }
/** * Called after record successfully created */ public function postCreate() { // Check if we should store creations in our revision history // Set this value to true in your model if you want to if (empty($this->revisionCreationsEnabled)) { // We should not store creations. return false; } if (!isset($this->revisionEnabled) || $this->revisionEnabled) { $changes_to_record = $this->changedRevisionableFields(); $newValue = array(); foreach ($changes_to_record as $key => $change) { $newValue[$key] = $this->updatedData[$key]; } $revisions[] = array('revisionable_type' => get_class($this), 'revisionable_id' => $this->getKey(), 'key' => 'created_at', 'old_value' => null, 'new_value' => json_encode($newValue), 'user_id' => $this->getUserId(), 'created_at' => new \DateTime(), 'updated_at' => new \DateTime(), 'ip' => \Request::ip()); $revision = new Revision(); \DB::table($revision->getTable())->insert($revisions); } }
/** * Called after record successfully created */ public function postCreate() { // Check if we should store creations in our revision history // Set this value to true in your model if you want to if (empty($this->revisionCreationsEnabled)) { // We should not store creations. return false; } if (!isset($this->revisionEnabled) || $this->revisionEnabled) { $revisions[] = array('revisionable_type' => $this->getMorphClass(), 'revisionable_id' => $this->getKey(), 'key' => self::CREATED_AT, 'old_value' => null, 'new_value' => $this->{self::CREATED_AT}, 'user_id' => $this->getSystemUserId(), 'created_at' => new \DateTime(), 'updated_at' => new \DateTime()); $revision = new Revision(); \DB::table($revision->getTable())->insert($revisions); \Event::fire('revisionable.created', array('model' => $this, 'revisions' => $revisions)); } }
/** * Called after a model is successfully saved. * * @return void */ public function postSave() { if (isset($this->historyLimit) && $this->revisionHistory()->count() >= $this->historyLimit) { $LimitReached = true; } else { $LimitReached = false; } // check if the model already exists if ((!isset($this->revisionEnabled) || $this->revisionEnabled) && $this->updating && !$LimitReached) { // if it does, it means we're updating $changes_to_record = $this->changedRevisionableFields(); $revisions = array(); foreach ($changes_to_record as $key => $change) { $revisions[] = array('revisionable_type' => get_class($this), 'revisionable_id' => $this->getKey(), 'key' => $key, 'old_value' => array_get($this->originalData, $key), 'new_value' => $this->updatedData[$key], 'user_id' => $this->getUserId(), 'created_at' => new \DateTime(), 'updated_at' => new \DateTime()); } if (count($revisions) > 0) { $revision = new Revision(); \DB::table($revision->getTable())->insert($revisions); } } }
/** * If softdeletes are enabled, store the deleted time */ public function postDelete() { if ((!isset($this->revisionEnabled) || $this->revisionEnabled) && $this->isSoftDelete() && $this->isRevisionable('deleted_at')) { $revisions = array(); $revisions[] = array('revisionable_type' => $this->getTable(), 'revisionable_id' => $this->getKey(), 'key' => 'deleted_at', 'old_value' => null, 'new_value' => $this->deleted_at, 'user_id' => $this->getUserId(), 'created_at' => new \DateTime()); $revision = new Revision(); \DB::table($revision->getTable())->insert($revisions); } }