I want to create e polymorphic relation, but when I add a relation I only find "Has One", "Has Many", "Belongs To", "Belongs To Many". How do I add a polymorphic relation in this case?
Voyager does not currently support polymorphic relationships. You're still free to use them in parallel to Voyager, but Voyager will not be able to maintain/control them.
@davodavodavo3's answer is correct. We may choose to implement this in a future release, but not in the foreseeable future.
Not in the foreseeable future?
IMHO, a serious Laravel oriented backend system should AIM to support all eloquent relationships.
I was digging packages for a while to find a well designed backend and i think Voyager has a real potential.
But, my projects are depends on various relationships at the model level to work properly and polymorphic relationship is one of them.
If i decide to go with Voyager either i have to refactor model base _(which is impossible for some reasons)_ or start to write blind coded implementations for adding polymorphic support to Voyager and take risk for incompatibility issues when a new release is present.
Without polymorphic relations, BREAD is useless if your app's logic require polymorphic relations at database level.
Will you think mark this issue as a feature request instead a question?
_Thank you for your valuable efforts._
@zeynelsalt I agree, however this is very much a community-driven project. I don't have time to implement that "in the foreseeable future", so it's up to the community to decide it's important enough to you and build it. Apologies if my previous message didn't convey it, but that was my intent.
I always admire those who spend their valuable time for community.
I've been studying Voyager for a few days and i think i am getting more familiar about how eloquent implementation is works.
Lets see what will happen in the coming days. I will let you know if there is a reliable implementation.
_Thanks and peace._
How would you go about using polymorphic relations in the voyager admin area? lets say I manually set these up in my model how would I include them in the voyager admin / database views ?
@futurewebsites Here's what I've done to make this work for me. First, check out https://laravelvoyager.com/academy/views/ on extending a view. In my example, I needed to be able to add multiple tags to a post, instead of being locked into 1 category. So, I made the tags and taggables table to handle the polymorphic relationship, updated the posts model, and extended the post edit-add view to handle the addition of the tags. Then I updated the controller to handle the addition of tags. Hope that helps!
@tetshi perfect thank you
any success? maybe a blog to share the result will benefit the community?
This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.
Most helpful comment
@futurewebsites Here's what I've done to make this work for me. First, check out https://laravelvoyager.com/academy/views/ on extending a view. In my example, I needed to be able to add multiple tags to a post, instead of being locked into 1 category. So, I made the tags and taggables table to handle the polymorphic relationship, updated the posts model, and extended the post edit-add view to handle the addition of the tags. Then I updated the controller to handle the addition of tags. Hope that helps!