Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

maximaexchen's avatar

Add custom subscription plans limitations problem

Hi everybody,

I posted a problem last week. But I am still stuck.

https://laracasts.com/discuss/channels/laravel/best-way-to-restict-the-amount-of-records-a-user-with-sepcific-subscription-plan-can-create

I need to have the possibility to check different subscription plans and than react on them in many controllers and views of the application. And each subscription plan has some different limitations creating amount records for different models and so on.

e.g. plan_1 an account can add/edit/view/list max 5 procedures-records and only can have one user and one client

plan_2 an account can add/edit/view/list max 20 procedures-records and only can have one user and 20 clients

...

plan_10 unlimited

etc.

Background info:

the subscription is added to an account, which is created when a user registers. An account has on or many users and clients.

I am still learning all that stuff and I am a bit confused how to handle this kind of programming challenge. For info, unfortunately I cannot use stripe because of the european "General Data Protection Regulation - GDPR". So I have to do subscription and payment stuff on my own.

So what I tried / I thought about

If I have policy, as I understand, it can only return true or false. If I do something like this in my policy;

class ProcedurePolicy
{
    public function max_procedures_items(User $user)
    {
        $account = Account::whereId(Auth::user()->account_id)->firstOrFail();
        $account->clients()->first()->procedures()->count();
        return $account->clients()->first()->procedures()->count() >= 5;
    }
}

So I have to do this for every different user with a different subscription plan, right? Does not feel right.

I thought about accessors and mutators, but this doesen't works "globally" in different controllers and views, right?

like so

class Account extends Model
{
    public $max_procedure_items = null;

    ...

    /**
     * Set max item number.
     *
     * @param  string  $value
     * @return void
     */
    public function setMaxProcedureItemsAttribute($value)
    {
        $this->attributes['max_procedure_items'] = $value;
    }

    /**
     * Get max item number.
     *
     * @param  string  $value
     * @return void
     */
    public function getMaxProcedureItemsAttribute($value)
    {
        return $value;
    }
}

Sessions?

I am lost. I hope this describes my knowlege problem understandable. I am not that good in programming design pattern, but is there one which could fit and usable in the laravel system?

Any hints, enlightenments, links, tutorials would be great. Thanks for reading.

Regards Marcus

0 likes
2 replies
ricardosawir's avatar

Hi @maximaexchen , hopefully I'm not too late for this. Recently, I also faced this issue, and like you, I also create a policy for this.

Basically, what you've done in the policy is correct in my opinion. and for the current state, we can also return Response::allow() or Response::deny() if needed more customized response.

Please or to participate in this conversation.