Skip to content

Conversation

@antonioribeiro
Copy link

@antonioribeiro antonioribeiro commented Oct 26, 2016

This change will allow us to have our own database schema (I need to add two other columns to the table) and by overloading the methods this way:

<?php

namespace App\Models\Revisions;

trait RevisionableTrait
{
    /**
     * @param $key
     * @return array
     * @throws \Exception
     */
    protected function makeRevision($key)
    {
        if ($this->table == 'users')
        {
            $user_id = $this->id;
        } else {
            $user_id = $this->user_id;
        }

        $study_id = ($study = ActiveStudy::get()) ? $study->id : null;

        return [
            'changed_user_id'   => $user_id,
            'study_id'          => $study_id,

            'revisionable_type' => $this->getMorphClass(),
            'revisionable_id'   => $this->getKey(),
            'key'               => $key,
            'old_value'         => array_get($this->originalData, $key),
            'new_value'         => $this->updatedData[ $key ],
            'user_id'           => $this->getSystemUserId(),
            'ip_address'        => request()->getClientIp(),
            'created_at'        => new \DateTime(),
            'updated_at'        => new \DateTime(),
        ];
    }
}
<?php

namespace App\Models\Revisions;

use App\Models\Base\Model;
use Venturecraft\Revisionable\RevisionableTrait as VenturecraftRevisionableTrait;

abstract class RevisionableModel extends Model
{
    use VenturecraftRevisionableTrait;

    use RevisionableTrait {
        RevisionableTrait::makeRevision insteadof VenturecraftRevisionableTrait;
    }
}

@stierler
Copy link
Collaborator

Sorry for delay in merging this in. There are a few other places that require the function to be called (ie. postCreate). I will update these when merged

@antonioribeiro antonioribeiro force-pushed the featureAllowOverloadOfRevisions branch 2 times, most recently from 2be740f to 3e6041e Compare May 30, 2017 23:30
@antonioribeiro antonioribeiro force-pushed the featureAllowOverloadOfRevisions branch from 3e6041e to dcb2659 Compare May 30, 2017 23:32
@antonioribeiro
Copy link
Author

@astierler, just made all the changes to support it. You just have to review them now :)
Thank you

@stierler stierler changed the base branch from master to develop May 31, 2017 02:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants