使用VentureCraft /可修改保留修订历史记录

时间:2014-05-14 15:24:53

标签: laravel laravel-4 revisionable

我必须显示在我的应用中进行的更改的历史记录(例如更新,插入 - >谁做了,更改了哪个字段以及何时更改)。我正在使用laravel 4,我也下载了this。但问题是我不知道如何使用它。文件夹VentureCraft放在哪里?以及如何获取执行操作的人员的用户名或ID。还有其他方法可以跟踪laravel的历史吗?

编辑:

汽车模型

namespace MyApp\Models;

class Car extends Eloquent {
    use \Venturecraft\Revisionable\RevisionableTrait;
}

查看

@foreach($description->revisionHistory as $history )
    <li>{{ $history->userResponsible()->username }} changed {{ $history->fieldName() }} from {{ $history->oldValue() }} to {{ $history->newValue() }}</li>
@endforeach

它显示: 未定义的变量:description

我在控制器中遗漏了什么吗?

1 个答案:

答案 0 :(得分:0)

查看README,它看起来相当自我解释。使用composer进行安装,迁移,然后使用您希望保留更新历史记录的模型中的RevisionableTrait。然后,您可以使用以下命令获取对象的历史记录:

 $object->revisionHistory;

他们甚至在刀片模板中有一个简单的使用示例:

@foreach($account->revisionHistory as $history )
    <li>{{ $history->userResponsible()->first_name }} changed {{ $history->fieldName() }} from {{ $history->oldValue() }} to {{ $history->newValue() }}</li>
@endforeach