0

我想知道如何在 CRUD 应用程序中使用VentureCraft/revisionable并获取历史记录

例如:用户每天都需要添加里程和编辑里程......在我看来(revision.blade.php)我想获取我尝试过添加和编辑但我不知道下一步该怎么做的历史?

这是模型

class Mileage extends Model
{
    use \Venturecraft\Revisionable\RevisionableTrait;
    protected $guarded = [];
}

这是路线

Route::get('/history', function () {
    $mileage = \App\Mileage::all();
    $history = $mileage->revisionHistory;
    return view('revision',compact('history'));
});

我不知道用什么代码来查看????

里程有 user_id,日期,里程我想这样显示

例如:用户 ...A... 已为 ..date.. 添加里程 .. 价值为 ...mileage...

如果他们编辑我想显示像这个用户...A...更新里程...日期...值是...里程...到...里程...我怎么能做这个 ?

4

2 回答 2

0
Route::get('/history', function () {
    $mileage = \App\Mileage::all();
    return view('revision',compact('mileage'));
});

现在在你的blade文件中

  @foreach($mileage->revisionHistory as $history )
    <p class="history">
      {{ $history->created_at->diffForHumans() }}, {{ $history->userResponsible()->name }} changed
      <strong>{{ $history->fieldName() }}</strong> from
      <code>{{ $history->oldValue() }}</code> to <code>{{ $history->newValue() }}</code>
    </p>
  @endforeach

现在,如果您需要controller在任何其他地方或任何其他地方的历史记录,您必须调用使用特征revisionHistory的实例modelRevisionableTrait

于 2016-04-20T12:30:50.083 回答
0

在显示历史之前。首先,可修订库假定在您的 Mileage 模型中,用户模型的关系方法称为 user(),因为 milage 表中的 FK 是 user_id。您还需要将以下代码添加到您的用户模型和里程模型。

public function identifiableName(){
    return $this->name;
}

在您看来,您需要像这样遍历历史数组。

@foreach($history as $h )
     <li>{{ $h->userResponsible()->first_name }} has updated milage  {{ $h->fieldName() }} from {{ $h->oldValue() }} to {{ $h->newValue() }}</li>
@endforeach
于 2016-04-20T12:14:04.427 回答