Inherits from BelongsTo.
- has the same capabilities
The MorphTo relationship field in Laravel
The same as MoonShine\Laravel\Fields\Relationships\BelongsTo
, but for MorphTo relationships
use MoonShine\Laravel\Fields\Relationships\MorphTo; //... protected function formFields(): iterable{ return [ MorphTo::make('Commentable')->types([ Article::class => 'title' ]), ];}//...
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; //... public function fields(): array{ return [ MorphTo::make('Imageable')->types([ Company::class => ['short_name', 'Organization'] ]), ];}//...