Skip to content
This repository was archived by the owner on Jul 16, 2021. It is now read-only.
This repository was archived by the owner on Jul 16, 2021. It is now read-only.

[Proposal] Use Macroable trait on eloquent models #1473

@imanghafoori1

Description

@imanghafoori1

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions