1

I have a morphMap setup in my AppServiceProvider boot method that is firing when the Laravel revisionable package calls for the record so nothing is being returned. I am looking to figure out how to make revisionable work with morphMaps. Please note that revisionable is storing the full namespace when saving the record but when calling the record revisionable is using the value I put in for the morphMap.

For example revisionable saves App\Models\Organization\Organization but my morphMap translates that to just organization when calling for the revisionHistory().

thestepafter
  • 598
  • 1
  • 4
  • 20

1 Answers1

0

I know this is an old question but I see Venturecraft/Revisionable developers are not giving answers to this problem.

The error ocurrs when the package try to instatiate a new model with the value of the property $this->revisionable_type in Venturecraft\Revisionable\Revision, because the class does't exist when using the key of $morphClass array instead of the real namespace of the model.

I figured out that the problem is solved when I override the value of this property with an Laravel Accessor like this:

use Illuminate\Database\Eloquent\Relations\Relation;

public function getRevisionableTypeAttribute($value)
{
    $morphedModel = Relation::getMorphedModel($value);
    return !empty($morphedModel) ? $morphedModel : abort(400, "The namespace {$value} hasn't been added to the Relation::morphMap() method.");
}

Now, I don't know how to add this Accessor to the Revision model without editing the one that comes in the vendor folder.

If you can give a try and share what you get will be helpful.

Carlos Torres
  • 53
  • 1
  • 6