Reputation: 143
I'm building a SaaS project using Symfony2, Doctrine2 and Postgresql. I have three different subscription plans, and for each plan there is a limit of members each user can store.
How can I limit a user to not store more members that the allowed for his subscription plan? Should I use a pre-persist event, counting the number of records belonging to her, and if there is an excess of records cancel the operation? Or this should be in the model or in the controller?
Upvotes: 1
Views: 152
Reputation: 19989
I recently had to build the same type of functionality for shouttag.com, where a user can only register X number of shouttags dependent upon their current billing plan. Granted, I am using Symfony/Doctrine 1.x, but the approach should be identical. Put the logic in the model layer, and whenever a user attempts to link a new member (via form save for example), issue a query for the user's current subscription plan, and how many members they currently have, if the resulting number is >= their allowed limit, then they cannot add more members until they change their subscription plan.
As an over-arching design goal you want to keep your controllers lean, and put most of your logic into your models (skinny controllers, fat models), this way the logic can be shared elsewhere throughout your code-base.
Upvotes: 3