Download the PHP package acolorstory/nova-polymorphic-field without Composer
On this page you can find all versions of the php package acolorstory/nova-polymorphic-field. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download acolorstory/nova-polymorphic-field
More information about acolorstory/nova-polymorphic-field
Files in acolorstory/nova-polymorphic-field
Package nova-polymorphic-field
Short Description A Laravel Nova field container allowing to depend on other fields values
License MIT
Informations about the package nova-polymorphic-field
Nova Polymorphic Field
Description
A Laravel Nova field that allows you to create a collection of polymorphic resources.
Depending on the polymorphic type you select:
- Different fields will be populated on the form/detail page of your resource.
- Records will be automatically created/updated in the corresponding tables.
Demo
Installation
The package can be installed through Composer.
Usage
- Add a
morphs
field to the migration of your base model. - Add the
MichielKempen\NovaPolymorphicField\HasPolymorphicFields
trait to your Nova Resource. - Add the
MichielKempen\NovaPolymorphicField\PolymorphicField
to your Nova Resourcefields
method. - Specify the different polymorphic types by calling the
type($name, $modelClass)
method on thePolymorphicField
.- The
$name
parameter is a readable name you assign to your polymorphic type. - The
$modelClass
parameter is the class of the polymorphic model.
- The
Example
Migrations:
Resource:
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.
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:
You may register the morphMap
in the boot
function of your AppServiceProvider
.
License
The MIT License (MIT). Please see License File for more information.