Closed dillingham closed 2 years ago
Hi @dillingham, there is a fundamental difference between the MorphTo field and the PolymorphicField.
The MorphTo field basically creates a link between two models, which each have their fields defined in their own Resource classes.
\App\Nova\NewsPost
contains all the fields of the \App\NewsPost
model.\App\Nova\Article
contains all the fields of the \App\Article
model.\App\Nova\Video
contains all the fields of the \App\Video
model.The PolymorphicField also creates a link between two models, but uses only one Resource class in which all the fields are defined.
\App\Nova\NewsPost
contains all the fields of the \App\NewsPost
, \App\Article
and \App\Video
model.
\App\NewsPost
are the ones defined in the fields()
method.\App\Article
and \App\Video
are the ones defined in the type()
method of the PolymorphicField
field.\App\Nova\Article
and \App\Nova\Video
.I understand. Im saying that if you were to have resources for Article
and Video
that it would be much cleaner to define them once and not in their resource and the post resource.
Wanting to see just articles
or just videos
will happen in some apps
Wanting to see all comments
but also see articles
and videos
separately
It is a great package for quickly creating the relationship But I really think it needs to use their fields like the MorphTo approach
PolyField::make('Type')->types([
\App\Nova\Video::class,
\App\Nova\Article::class
])
PolyField::make('Commentable')->types([
\App\Nova\Video::class,
\App\Nova\Article::class,
\App\Nova\Event::class,
\App\Nova\Listing::class,
\App\Nova\Item::class,
])
I may not fully understand this package honestly lol 😅
Hi @michielkempen . Have you got any more thoughts on this?
My first thought was also that it would be nicer to pass Nova resources into the types instead of re-defining the fields, like @dillingham has described.
Hi,
There is small workoround for it.
Start using https://nova.laravel.com/docs/1.0/resources/relationships.html#morphtomany part of
MorphToMany::make('Users')->fields(new TaggableFields) where TaggableFields is class that you can reuse
Then call it like this, yes it is dirty as hell :)
@dillingham I think this is just what you are (were) looking for: https://github.com/dcasia/nova-inline-morph-to
Any chance the fields could be automatically detected from the resource? like morphTo