Fields

MorphTo

Inherits from BelongsTo.

* has the same capabilities.

Relationship field in Laravel of type MorphTo.

use MoonShine\Laravel\Fields\Relationships\MorphTo;
 
MorphTo::make('Commentable')->types([
Article::class => 'title'
])
use MoonShine\Laravel\Fields\Relationships\MorphTo;
 
MorphTo::make('Commentable')->types([
Article::class => 'title'
])

morph_to morph_to_dark

The types() method is required, specifying the available classes.

Description of the types method value:

  • Key - class-string<Model>
  • Value - string or array.

If the value is passed as a string, it should point to the name of the field to be displayed. If passed as an array, the first element of the array is the name of the field to display, and the second is the relationship name instead of the model name.

use MoonShine\Fields\Relationships\MorphTo;
 
MorphTo::make('Imageable')->types([
Company::class => ['short_name', 'Organization']
])
use MoonShine\Fields\Relationships\MorphTo;
 
MorphTo::make('Imageable')->types([
Company::class => ['short_name', 'Organization']
])

morph_to_array morph_to_array_dark