PHPackages                             acolorstory/nova-polymorphic-field - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. acolorstory/nova-polymorphic-field

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

acolorstory/nova-polymorphic-field
==================================

A Laravel Nova field container allowing to depend on other fields values

1.0.6(7y ago)024MITPHPPHP &gt;=7.1.0

Since Sep 18Pushed 6y agoCompare

[ Source](https://github.com/acolorstory/nova-polymorphic-field)[ Packagist](https://packagist.org/packages/acolorstory/nova-polymorphic-field)[ RSS](/packages/acolorstory-nova-polymorphic-field/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (8)Used By (0)

Nova Polymorphic Field
======================

[](#nova-polymorphic-field)

[![Latest Version on Packagist](https://camo.githubusercontent.com/bfe1a4407ad1c25f60328f26d84ea97ee0774c9386ef2b4a2bb964decc6502a5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d69636869656c6b656d70656e2f6e6f76612d706f6c796d6f72706869632d6669656c642e737667)](https://packagist.org/packages/michielkempen/nova-polymorphic-field)[![Total Downloads](https://camo.githubusercontent.com/88f188288de2ece6d9047d6969d2b96f967d9670d96ebea8ceef0b02fb064b95/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d69636869656c6b656d70656e2f6e6f76612d706f6c796d6f72706869632d6669656c642e737667)](https://packagist.org/packages/michielkempen/nova-polymorphic-field)[![License](https://camo.githubusercontent.com/16287ce0a1cd8bc820d5e0970a84143f792cfbc17c8fc250d92dd92ff89de91b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d69636869656c6b656d70656e2f6e6f76612d706f6c796d6f72706869632d6669656c642e737667)](https://github.com/michielkempen/nova-polymorphic-field/blob/master/LICENSE.md)

### Description

[](#description)

A Laravel Nova field that allows you to create a **collection of polymorphic resources**.

Depending on the polymorphic type you select:

1. Different fields will be populated on the form/detail page of your resource.
2. Records will be automatically created/updated in the corresponding tables.

[![Scheme](https://raw.githubusercontent.com/michielkempen/nova-polymorphic-field/master/docs/scheme.png)](https://raw.githubusercontent.com/michielkempen/nova-polymorphic-field/master/docs/scheme.png)

### Demo

[](#demo)

[![Scheme](https://raw.githubusercontent.com/michielkempen/nova-polymorphic-field/master/docs/demo.gif)](https://raw.githubusercontent.com/michielkempen/nova-polymorphic-field/master/docs/demo.gif)

### Installation

[](#installation)

The package can be installed through Composer.

```
composer require michielkempen/nova-polymorphic-field
```

### Usage

[](#usage)

1. Add a `morphs` field to the migration of your base model.
2. Add the `MichielKempen\NovaPolymorphicField\HasPolymorphicFields` trait to your Nova Resource.
3. Add the `MichielKempen\NovaPolymorphicField\PolymorphicField` to your Nova Resource `fields` method.
4. Specify the different polymorphic types by calling the `type($name, $modelClass)` method on the `PolymorphicField`.
    - The `$name` parameter is a readable name you assign to your polymorphic type.
    - The `$modelClass` parameter is the class of the polymorphic model.

### Example

[](#example)

Migrations:

```
Schema::create('news_posts', function (Blueprint $table) {
    $table->increments('id');
    $table->string('title');
    $table->morphs('type'); // !!
    $table->timestamps();
});

Schema::create('videos', function (Blueprint $table) {
    $table->increments('id');
    $table->string('url');
});

Schema::create('articles', function (Blueprint $table) {
    $table->increments('id');
    $table->string('image');
    $table->text('text');
});
```

Resource:

```
class NewsPost extends Resource
{
    use HasPolymorphicFields;

    public function fields(Request $request)
    {
        return [

            Text::make('Title'),

            PolymorphicField::make('Type')
                ->type('Video', \App\Video::class, [

                    Text::make('Url'),

                ])
                ->type('Article', \App\Article::class, [

                    Image::make('Image'),

                    Textarea::make('Text'),

                ]),

        ];
    }
}
```

You can optionally hide the type selection when updating a resource. This can be useful if you don't want the user to be able to change the **Type** of a polymorphic relationship once it has been created.

```
class NewsPost extends Resource
{
    use HasPolymorphicFields;

    public function fields(Request $request)
    {
        return [
            ...
            PolymorphicField::make('Type')
                ->type('Video', \App\Video::class, [
                    Text::make('Url'),
                ])
                ->type('Article', \App\Article::class, [
                    Image::make('Image'),
                    Textarea::make('Text'),
                ])
                ->hideTypeWhenUpdating(),
            ...
        ];
```

### morphMap

[](#morphmap)

By default, the fully qualified class name of the related model will be stored as type field in the base model. However, you may wish to decouple your database from your application's internal structure. In that case, you may define a relationship "morph map" to instruct Eloquent to use a custom name for each model instead of the class name:

```
use Illuminate\Database\Eloquent\Relations\Relation;

Relation::morphMap([
    'article' => \App\Article::class,
    'video' => \App\Video::class,
]);
```

You may register the `morphMap` in the `boot` function of your `AppServiceProvider`.

### License

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/michielkempen/nova-polymorphic-field/blob/master/LICENSE.md) for more information.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 53.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~8 days

Total

7

Last Release

2742d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/79b4dc4f891e9d8dcfbcd9c638381dbcb437ac84de2565761245077ebb23690e?d=identicon)[miguelsolano-acs](/maintainers/miguelsolano-acs)

---

Top Contributors

[![michielkempen](https://avatars.githubusercontent.com/u/14795113?v=4)](https://github.com/michielkempen "michielkempen (24 commits)")[![miguelsolano-acs](https://avatars.githubusercontent.com/u/45976575?v=4)](https://github.com/miguelsolano-acs "miguelsolano-acs (10 commits)")[![m2de](https://avatars.githubusercontent.com/u/17720020?v=4)](https://github.com/m2de "m2de (4 commits)")[![mbardelmeijer](https://avatars.githubusercontent.com/u/1583095?v=4)](https://github.com/mbardelmeijer "mbardelmeijer (4 commits)")[![jasonlav](https://avatars.githubusercontent.com/u/7593912?v=4)](https://github.com/jasonlav "jasonlav (3 commits)")

---

Tags

laravelnova

### Embed Badge

![Health badge](/badges/acolorstory-nova-polymorphic-field/health.svg)

```
[![Health](https://phpackages.com/badges/acolorstory-nova-polymorphic-field/health.svg)](https://phpackages.com/packages/acolorstory-nova-polymorphic-field)
```

###  Alternatives

[optimistdigital/nova-multiselect-field

A multiple select field for Laravel Nova.

3403.5M7](/packages/optimistdigital-nova-multiselect-field)[digital-creative/conditional-container

Provides an easy way to conditionally show and hide fields in your Nova resources.

116593.8k4](/packages/digital-creative-conditional-container)[genealabs/laravel-overridable-model

Provide a uniform method of allowing models to be overridden in Laravel.

92398.0k2](/packages/genealabs-laravel-overridable-model)[inspheric/nova-defaultable

Default values for Nova fields when creating resources and running resource actions.

51174.8k1](/packages/inspheric-nova-defaultable)[murdercode/nova4-tinymce-editor

Boost your Laravel Nova with the TinyMCE editor.

17165.2k](/packages/murdercode-nova4-tinymce-editor)[yieldstudio/nova-google-autocomplete

A Laravel Nova Google autocomplete field.

12218.4k](/packages/yieldstudio-nova-google-autocomplete)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
