I’ve built a role module (package) where I’ve used the HasRole trait in the User model. Now, I’m trying to remove the HasRole trait from the User model and add it to the role package’s service provider.
I’ve looked around for solutions but haven’t found anything helpful. I stumbled upon a package called Traitor, but I’m unsure about its reliability.
Could you provide any advice on how to achieve this smoothly and reliably? Thank you!
2
Answers
You should not remove your dependencies totally. You need to be depend on abstraction instead of concrete class.
You are writing monolith application considering separation of concerns.
You don’t have to worry about separation at service levels.
If you have concerns about services it’s ok. Welcome to micro services world. You should call your services with protocols like http, gRPC and…
You don’t need any of that, this is very simple to do:
Traits
directory, and inside it store your traits and assign each trait to the namespace of the package, for example:User
model, just refer to the trait by its qualified name:Or maybe:
And that’s all about it, no need to overcomplicate things