Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shouldn't use original data in postCreate #431

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/Venturecraft/Revisionable/RevisionableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public function postCreate()

//Determine if there are any additional fields we'd like to add to our model contained in the config file, and
//get them into an array.
$revisions = array_merge($revisions[0], $this->getAdditionalFields());
$revisions = array_merge($revisions[0], $this->getAdditionalFields(false));

$revision = Revisionable::newModel();
\DB::table($revision->getTable())->insert($revisions);
Expand Down Expand Up @@ -339,15 +339,17 @@ public function getSystemUserId()
}


public function getAdditionalFields()
public function getAdditionalFields($useOriginalData = true)
{
$additional = [];
// If this is coming from postCreate, we shouldn't use original data as there is no original data.
$dataToUse = $useOriginalData ? $this->originalData : $this->toArray();
//Determine if there are any additional fields we'd like to add to our model contained in the config file, and
//get them into an array.
$fields = config('revisionable.additional_fields', []);
foreach($fields as $field) {
if(Arr::has($this->originalData, $field)) {
$additional[$field] = Arr::get($this->originalData, $field);
if(Arr::has($dataToUse, $field)) {
$additional[$field] = Arr::get($dataToUse, $field);
}
}

Expand Down