Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions src/Venturecraft/Revisionable/Revision.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,8 @@ public function format($key, $value)
return $value;
}
}

public function user(){
return $this->belongsTo(app('config')->get('auth.model'), 'user_id','id');
}
}
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