gerardojbaez / laraplans

SaaS style recurring plans for Laravel.
http://laraplans.readthedocs.io
MIT License
180 stars 81 forks source link

Plan Subscriber forced to be `User` #18

Closed Acen closed 6 years ago

Acen commented 7 years ago

Both the traits and migrations directly reference User models, which removes the point of building it into a Trait.

A person may want to integrate their subscriptions on a different kind of Model.

gerardojbaez commented 6 years ago

Thanks for taking the time to report the issue.

Sorry for the delay in the reply.

I don't see a direct reference to User model in the Gerardojbaez\LaraPlans\Traits\PlanSubscriber trait, only in the migration for plan_subscriptions table. If we remove the foreign key of user_id that is creating a link between users table and plan_subscriptions table, we should be able to use other models as the subscriber. This is how Cashier handles this. What do you think?

gerardojbaez commented 6 years ago

I think using the Polymorphic relation in subscriptions table will be a better approach, this way we can have multiple subscribable models at the same time.

Acen commented 6 years ago

Baha, was thinking when I saw the notification for this "ayy, someone reported this issue. I remember thinking this while looking through the codebase". Good stuff getting to it eventually. I've just been implementing Polymorphic relationships in a new code base, they are great for this sort of thing.