2

I am using VentureCraft/revisionable in my Laravel project. I wanted to work on multiple models at once, but since revisionable doesn't allow me to do so, I did that in single models.

There was this one instance, where I got this revisionable output as this

Chris changed status from 4 to 5.

But, instead this, I wanted something like this:

Chris changed status from New to In progress.

4 and 5 were the foreign keys to the name New and In progress.

How can I use foreign value relations in revisionable.

nirvair
  • 4,001
  • 10
  • 51
  • 85

2 Answers2

1

I've never used this package, but looking at the documentation it looks like you need to implement the identifiableName() method in the related model. Instead of displaying the foreign keys, it will display whatever is returned from the identifiableName() method.

So, if your related model is Status, you would do something like:

class Status extends Eloquent {
    use Venturecraft\Revisionable\RevisionableTrait;

    public function identifiableName() {
        return $this->name;
    }
}
patricus
  • 59,488
  • 15
  • 143
  • 145
  • What if there are multiple foreign keys? – nirvair Aug 20 '15 at 05:26
  • @phantomphoenix You would need to provide some code and more explanation of what you're trying to do. My understanding is that you have something like a `Task` model that `belongsTo` `Status` (task has the `status_id`). When the `status_id` on the task changes, the revision history will look up the status record, and print the value from the `identifiableName()` method. So, I'm not sure what problem you're trying to solve. – patricus Aug 20 '15 at 05:40
  • Sadly this doesn't work. I have tried various things to get indentifiableName() working but without any success. – Flobbo May 09 '16 at 09:13
0

Do what @patricus said but instead of

    return $this->name;

point to the value you want revisionable to display

    return $this->[whatever field you have in the db];