Wave: How do I apply subscription level restrictions?
Hi, Just started lookinginto wave afor a project I am building. I love the structure and everything that it alread offers, top job. What I wanted to know however is with all the subscriptions. How would I go about adding restrictions to each subscription level and role, and then apply those inside my account?
Would it simply be a matter of adding these as permissions and then checking the permissions?
My idea revolves around restricting numbers of things that can be achieved, for instance if we use the "projects" example in the documentation I would like to restrict the basic plan to being able to add only 3 projects inside a calendar month and so on.
I have the queries in place to do this manualy and can restrict everything however I would love to be able to put an subscription level restriction in place and then be able to simply do a something like
if($projectCount < $planRestrictionCount)
{
//Show add more button
}
a rudimentary example but I guess I am missing this step on how I can feature restrict without it being a permission.
Forgive me if this has already been asked, I couldn't find the search
Thanks Dan
Hey @dannymh,
Thanks for the question. Here's how I would do it. I would add a method to the User model, something like:
public function canCreateProject(): bool
{
$plan = $this->roles->first()->name ?? 'free';
$allowedProjects = match ($plan) {
'basic' => 3,
'premium' => 5,
'pro' => 10,
default => 0,
};
return $this->projects()->count() < $allowedProjects;
}
Now, you can check if the user can create a project by running:
if(auth()->user()->canCreateProject()){
// you can create a project
} else {
// you cannot create a project
}
Let me know if that helps and let me know if you have any follow-ups.
Thanks!
This will work for what I am trying to do. The only issue I have is scalability of this.
Ideally over time I will build in an interface or maybe integrate in filiment somthing like pennant to try and capture feature flags and settings.
The idea is that we can tie plan limits or role level limits into the platform that can easily be adjusted and reflected in the functionality and rest of the platform.
As you start and scale the SaaS there are always going to be tweaks and adjustments to the plan rules and feature sets, most of those wont be in code, but simply plan limits that should be able to be easily tweaked in the interface and therefore applied in code.
Thanks for your help, in the short term this will get me up and running whilst I look at building and interface for managing features
Dan