2

您好,在我的项目中,我使用 VentureCraft/revisionable https://github.com/VentureCraft/revisionable这是记录数据库中记录更改历史的补充。一切正常,但是当我在页面上返回历史记录时,脚本以 id 的形式返回结果。这是我的表“products” products_table这是表“revisions” revisions_table此表连接到表:文章、用户和类别。现在历史更改如下所示:

“用户 1 将姓名文章从 2 更改为 1”

我希望历史更改看起来像:

“用户 JACK 将名称文章从 SHOES 更改为 BALL”

我尝试使用此链接

带有文件 Revisionable.php 的方法 identifiableName() 如下所示:

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

在模型 product.php 中,我添加了:

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

或这个:

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

但它不起作用。

4

2 回答 2

1

好的,我找到了解决此问题的方法:仅使用: whereId或 示例:findfaindOrFail

article::whereId( $hist->old_value )->first()->article_name

或者

article::find( $hist->old_value )->article_name

或者

article::findOrFail( $hist->old_value )->article_name

article:name文章表中的名称列在哪里。

于 2016-07-19T15:25:37.533 回答
1

您可以使用

$history->userResponsible()->first_name

就像文档说的

@foreach($resource->revisionHistory as $history)
  @if($history->key == 'created_at' && !$history->old_value)
    <li>{{ $history->userResponsible()->first_name }} created this resource at {{ $history->newValue() }}</li>
  @else
    <li>{{ $history->userResponsible()->first_name }} changed {{ $history->fieldName() }} from {{ $history->oldValue() }} to {{ $history->newValue() }}</li>
  @endif
@endforeach

或者如果您想将其用作响应 api,您可以操纵响应以获取它们的关系

$response = $question->revisionHistory->map(function($history) {
            return ['history' => $history, 'users' => $history->userResponsible()];
        });
return response()->json($response);
于 2019-02-28T12:04:02.243 回答