4 years ago

How can I Make Relations Modular for package development?

Posted 4 years ago by Abid

I'm trying to build some modular packages to simplify my workflow when trying to support multiple projects. Their are some problem I'm facing, but right now the main problem I'm having is with the Eloquent Part and making relations in a modular way.

So I took out the App\User and placed them in my modular package User modules Model directory, So its new place is Module\User\Model\User. I have another Model UserProfile in that same place and because of it, I can put the relations out their because it is part of that same module.

However there is a Acl module which is dependent on the User module and has Role model. Because of it I can add relation to the Role model with User model, but can't do the same in the User model with Role, because User module is not dependent on Acl module. To add the relation on User with Role, I have to add code in the User and that's what I wanted to avoid. What if one of my app doesn't need Acl?

Also what happens when I start to add Blog, News, Comments etc. Do I have to add relations on the User model for all of them? What if one of them doesn't require News module, should my news relation codes still stays in the User model.

I really want to use Eloquent because of some of its great features when dealing with saving relation based data. If there is a simple solution on how to avoid adding tons of relations on the User model, do please guide me. Also this is not just about User model, it could be on any model when working with modular application (or packages in my case).

Please sign in or create an account to participate in this conversation.