Winter CMS resources and help articles

Simple and to the point. Optimized by the community.

Using morphMap to migrate morph-type relations to another model

1
by mjauvin, last modified on August 7th, 2023

If you need to migrate morph-type relations that store the model name in the DB, morphMap is really good for this.

That will also take care of translated model fields stored in winter_translate_attributes table.

The following morphMap migrates the relations from Lovata.Shopaholic plugin to OFFLINE.Mall plugin:

use Winter\Storm\Database\Relations\Relation;

public function boot()
{
    Relation::morphMap([
        'Lovata\Shopaholic\Models\Product'  => 'OFFLINE\Mall\Models\Product',
        'Lovata\Shopaholic\Models\Category' => 'OFFLINE\Mall\Models\Category',
    ]);
}

Discussion

0 comments

We use cookies to measure the performance of this website. Do you want to accept these cookies?