PHPackages                             moneo/laravel-morphmap - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. moneo/laravel-morphmap

ActiveLibrary[Database &amp; ORM](/categories/database)

moneo/laravel-morphmap
======================

Custom morphMap support for Laravel Framework

v2.0.0(1mo ago)521.6k2MITPHPPHP ^8.1CI passing

Since Mar 5Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/moneo/laravel-morphmap)[ Packagist](https://packagist.org/packages/moneo/laravel-morphmap)[ RSS](/packages/moneo-laravel-morphmap/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (5)Versions (7)Used By (0)

[![](https://camo.githubusercontent.com/36989774208f939d5cef17522263dfe1d3b05416ecc64f4323c20d485416974d/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f437573746f6d2532304d6f7270682532304d61702e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d6d6f6e656f2532466c61726176656c2d6d6f7270686d6170267061747465726e3d616e63686f727341776179267374796c653d7374796c655f31266465736372697074696f6e3d437573746f6d2b6d6f7270684d61702b666f722b656163682b72656c6174696f6e266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d6c696e6b)](https://camo.githubusercontent.com/36989774208f939d5cef17522263dfe1d3b05416ecc64f4323c20d485416974d/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f437573746f6d2532304d6f7270682532304d61702e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d6d6f6e656f2532466c61726176656c2d6d6f7270686d6170267061747465726e3d616e63686f727341776179267374796c653d7374796c655f31266465736372697074696f6e3d437573746f6d2b6d6f7270684d61702b666f722b656163682b72656c6174696f6e266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d6c696e6b)

Laravel Custom Morph Map
========================

[](#laravel-custom-morph-map)

[![Tests](https://github.com/moneo/laravel-morphmap/actions/workflows/php.yml/badge.svg)](https://github.com/moneo/laravel-morphmap/actions/workflows/php.yml)[![Latest Stable Version](https://camo.githubusercontent.com/93d9a9889759f3ae56a4ae5776af94f3db061efddcf4fef3d27fa2520b99e0a2/68747470733a2f2f706f7365722e707567782e6f72672f6d6f6e656f2f6c61726176656c2d6d6f7270686d61702f76)](https://packagist.org/packages/moneo/laravel-morphmap)[![License](https://camo.githubusercontent.com/ce6e36fe110680d89ab8e499f81a3c457ca9347d7e20a2ec026b78fccf4854c7/68747470733a2f2f706f7365722e707567782e6f72672f6d6f6e656f2f6c61726176656c2d6d6f7270686d61702f6c6963656e7365)](https://packagist.org/packages/moneo/laravel-morphmap)

Use **different morph maps for different relationships** on the same model.

By default, Laravel's `Relation::morphMap()` applies globally to all polymorphic relationships. This package lets you define a custom morph map **per relationship**, so different polymorphic relations on the same model can use different type aliases.

Requirements
------------

[](#requirements)

VersionPHPLaravel2.x^8.110, 11, 121.x&gt;=8.08, 9, 10, 11Installation
------------

[](#installation)

```
composer require moneo/laravel-morphmap
```

No service provider registration is needed. Just use the trait.

Usage
-----

[](#usage)

Add the `HasCustomMorphMap` trait to your model and define the `$customMorphMap` property in your constructor.

The array keys are the **related model's fully qualified class name**, and the values are the **morph type alias** you want stored in the database for that relationship:

```
