現在、これを行うネイティブな方法はありませんが、いくつかのオプションがあります。私はModelBのは、MODELAにセーブ添付するために必要な特定のモデルに何をすべきか(または任意のシナリオ)クラスのグローバル関数を作った(またはhelpers.phpに使用)これを行うにされています。後で呼び出すだけ次に
/**
* Creates a revision record.
*
* @param object $obj
* @param string $key
* @param mixed $old
* @param mixed $new
*
* @return bool
*/
public static function createRevisionRecord($obj, $key, $old = null, $new = null)
{
if (gettype($obj) != 'object') {
return false;
}
$revisions = [
[
'revisionable_type' => get_class($obj),
'revisionable_id' => $obj->getKey(),
'key' => $key,
'old_value' => $old,
'new_value' => $new,
'user_id' => vms_user('id'),
'created_at' => new \DateTime(),
'updated_at' => new \DateTime(),
]
];
$revision = new \Venturecraft\Revisionable\Revision;
\DB::table($revision->getTable())->insert($revisions);
return true;
}
をsave()
フックからMyHelperClass::createRevisionRecord()
public function save(array $options = [])
{
// $old = $this->getOriginal('key');
// $new = $this->key;
// Let's say this is linked to \App\SomethingElse via 'something_id'
MyHelperClass::createRevisionRecord(\App\SomethingElse::find($this->something_id), 'custom_field', $old, $new);
// Do actual save.
return parent::save($options);
}
これは最もエレガントな方法ではありませんが、それは私の最初の仕事のハッキーオプションでした。
Revisionable v2.0 +には、作業中の組み込み機能が組み込まれています!
ありがとう、@Austin。私は自分のハッキーなソリューションをコーディングすることになりましたが、私はあなたのことがもっと好きです。ありがとう! – brianfr82