The fact that laravel packages (or laravel modules in other words) can not introduce new relations on the models that exist in the other modules *without touching their code) creates coupling problems.
For example if we have a commenting package which has a Comment model and some migrations to hold comments in a comments table.
when installed there is no way, except to expose a trait to put on the User model to reflect the relation between Comments and User. Ok this is not the end of the world, we can live with it.
We use the trait and $user->comments would be accessible.
But, when we add an other package to help us have like and dislike on the Comment model.
then how to put the trait on a model which already exists within the vendor folder ?!
From the theoretical point of view, this is violating the open-close principle.
For example, when you start to modularize your application with :
https://github.com/nWidart/laravel-modules
you immediately realize that models in different modules can not be totally decoupled.
When you add a add a comment module : the User module code should change to define new relations.
then when you add like module both the comment and user module code should be modified.
The fact that laravel packages (or
laravel modulesin other words) can not introduce new relations on the models that exist in the other modules *without touching their code) creates coupling problems.For example if we have a
commentingpackage which has aCommentmodel and some migrations to hold comments in acommentstable.when installed there is no way, except to expose a trait to put on the
Usermodel to reflect the relation between Comments and User. Ok this is not the end of the world, we can live with it.We use the trait and
$user->commentswould be accessible.But, when we add an other package to help us have
likeanddislikeon theCommentmodel.then how to put the trait on a model which already exists within the vendor folder ?!
From the theoretical point of view, this is violating the
open-close principle.For example, when you start to modularize your application with :
https://github.com/nWidart/laravel-modules
you immediately realize that models in different modules can not be totally decoupled.
When you add a add a comment module : the User module code should change to define new relations.
then when you add
likemodule both the comment and user module code should be modified.